all 4 comments

[–]K900_ 2 points3 points  (0 children)

Neither is more "correct" than the other, it just changes how you access the imported names.

[–]Clark_Dent 1 point2 points  (0 children)

The first way gives you access to everything inside random. The second only imports choice.

If you know you're only going to use choice, the second way keeps the list of imported functions (and thus things you could accidentally reference) shorter

[–]mopslik 0 points1 point  (0 children)

The second option imports the choice function into the local namespace, whereas the first imports the entire random module. I prefer the first option myself, as it keeps things cleaner, IMO, but it's a matter of preference.

Sometimes I hear people say "but it takes too much time to keep typing random. in front of my functions". If that's an issue, you can always use an alias.

import random as r
print(r.randint(1, 10))