I can not find a meaning that is useful for me to know when to use it I would like you to help me, since I need it for a subject at the university. In summary: Could you explain how and when to use the from and the import?
I can not find a meaning that is useful for me to know when to use it I would like you to help me, since I need it for a subject at the university. In summary: Could you explain how and when to use the from and the import?
With import
what we do is import modules from the library.
I'll explain it to you with a simple and practical example.
If we want to generate random numbers, we have two options, or we invent an algorithm that generates them or we use an existing one.
What is more comfortable? - Use the existing one.
How do we bring it? - Using import
.
In this case we would do:
import random
print(random.randrange(10))
But this can go further, if we simply want a single function of the module, we can simply bring that.
How do we do it? - Using import
and from
.
For example we want to generate random but that is concretely whole.
from random import randint
print(randint(10, 20))
Here I leave you many different modules that exist from the standard library Link