+ 1

Why do I need to import modules first?

Can't I just write modules directly to do whatever I want? Pls explain why I can't do this.Thx!!!

17th Dec 2016, 2:37 PM
YuHai
YuHai - avatar
4 Respostas
+ 2
Try import.random Don't forget the period, it is needed to run a module.
18th Dec 2016, 1:36 AM
luc_gar
luc_gar - avatar
+ 1
What do you mean? You can write your own. Just create a new Python file (.py) and write your code there. Then import it using the import command as you would with any other modules.
17th Dec 2016, 4:10 PM
luc_gar
luc_gar - avatar
0
Sorry!It's my fault. What I mean is before I type for i in range(5): print(random.randint(1,5)) I need to type "import random" first. Isn't it already built in python?
17th Dec 2016, 6:05 PM
YuHai
YuHai - avatar
0
thx!!!
18th Dec 2016, 4:41 AM
YuHai
YuHai - avatar