0

How to use from keyword in python

how to use from keyword in Python or tell me how to use from random import randrange how to use it give me some examples

23rd Sep 2018, 6:13 AM
Sainath Dora
2 Antworten
+ 4
"from <module> import <submodule>" allows you to import a certain submodule (=> randrange) from a module (=> random). "import random" imports all the submodules from random and you can use random.randrange, random.gauss etc. in your code to access these submodules. "from random import randrange" will only import randrange and you can access it with "randrange" (no need to write "random.randrange" (<= in fact that would be wrong)). But you won't be able to use random.randint(), random.random() or other submodules because you only imported randrange.
23rd Sep 2018, 6:32 AM
Anna
Anna - avatar
+ 1
thanks
23rd Sep 2018, 7:17 AM
Sainath Dora