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 *

21st Jul 2018, 10:24 AM
Sainath Dora
6 odpowiedzi
+ 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))
21st Jul 2018, 10:31 AM
Satyam
+ 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
21st Jul 2018, 1:32 PM
HonFu
HonFu - avatar
+ 2
you are welcome. I hope you understand my explanation.
21st Jul 2018, 12:50 PM
Satyam
+ 1
thanks a lot
21st Jul 2018, 12:37 PM
Sainath Dora
+ 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.
21st Jul 2018, 12:56 PM
Satyam
0
so what if used random.randint(x, y) even after using from random import *
21st Jul 2018, 12:53 PM
Sainath Dora