Radnint Function doubt PYTHON


#1

Hello!

What is the difference in writing:

r = randint(1, 10)

and

r = random.randint(1, 10)

Was trying both ways and both it gave me a random number, however not sure if there is actully a difference.


#2

depends on how you import the randint function from the math module.

if you do:

from math import randint`

the random integer function is within your global namespace, and can be called like so:

r = randint(1, 10)

if you import the whole math module:

import random

all functions of the math module can be access using the following general syntax: modulename.functionname.

that the function are “prefixed” with the module name is very useful for when your python project start to grow, what if you import the function directly (from math import * or from math import randint) and you import two functions with the same name from different modules?


#3

Great! Thank you very much.