0
What is the difference between import random and from random import *
What is the difference between import random and from random import * i saw a video in that they used What is the difference between import random and from random import *
6 Antworten
+ 3
If you just do import random, you have to use random.{method} to do a task. For example,
import random
print(random.randint(1,4))
If you do from random import *, you do not need to do, random.{method}, you can just do {method}. For example,
from random import *
print(randint(1,4))
+ 3
If anyone stumbles over this... I have an unanswered 'follow-up' question about the topic myself ... ^o^
https://www.sololearn.com/discuss/1415375/?ref=app
+ 2
you are welcome. I hope you understand my explanation.
+ 1
thanks a lot
+ 1
Try it on your own! It's best to learn by self.
But here's a thing, from random import * is not recommended in most cases. I suggest you stick to import random unless you know what you are doing.
0
so what if used random.randint(x, y) even after using from random import *