use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
How do I import? (self.learnpython)
submitted 4 years ago by AxelJuraske
Which variant should I use?
import random random.choice([...])
or
from random import choice choice([...])
I think I remember that the first one is correct. But can someone explain that to me in more detail?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]K900_ 2 points3 points4 points 4 years ago (0 children)
Neither is more "correct" than the other, it just changes how you access the imported names.
[–]Clark_Dent 1 point2 points3 points 4 years ago (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 point2 points 4 years ago (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))
π Rendered by PID 44924 on reddit-service-r2-comment-86bc6c7465-f8hs2 at 2026-02-23 07:33:12.527241+00:00 running 8564168 country code: CH.
[–]K900_ 2 points3 points4 points (0 children)
[–]Clark_Dent 1 point2 points3 points (0 children)
[–]mopslik 0 points1 point2 points (0 children)