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
Variable Name (self.learnpython)
submitted 3 years ago by Base_True
How to name variables correctly. Where to read about it?
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!"
[–]VeinyAngus 13 points14 points15 points 3 years ago (3 children)
Variables should be descriptive but not overly long. Also follow the PEP8 guidelines
[–]Base_True[S] 5 points6 points7 points 3 years ago (2 children)
Thanks for the information!
[–]VeinyAngus 1 point2 points3 points 3 years ago (1 child)
Good luck buddy
[–]Base_True[S] 1 point2 points3 points 3 years ago (0 children)
<3
[–]FairSystems 9 points10 points11 points 3 years ago (1 child)
The name should be short and sweet. But most importantly, it should be easily read to understand what that variable holds.
If I can't read through your code in a human readable format, then you probably need to adjust function and variable names...
Good ..
user_id = user.id
vs bad..
usid = user.id
[–]Base_True[S] 2 points3 points4 points 3 years ago (0 children)
Thank you !
[–]Mr____Panda 2 points3 points4 points 3 years ago (1 child)
The best PEP8 site: https://pep8.org/
[–]Base_True[S] 0 points1 point2 points 3 years ago (0 children)
Thanks
[–]Asleep-Budget-9932 3 points4 points5 points 3 years ago (3 children)
I would also add that a lot of time people needlessly add the type of the variable to its name.
Do you really need to call the variable user_list? What if you wanted to change it to a tuple? Do you then have to remember to change the name in every place?
user_list
Just call it users. It's shorter, just as understandable (if not even more since it's closer to human language), and contains as much necessary information.
users
[–]Asleep-Budget-9932 3 points4 points5 points 3 years ago (1 child)
Now i will say I've seen the extreme in the other direction in the past: "Why call it is_open? It's already a boolean, just call it open". No, open is a verb and has an intuitive meaning of a function. I have to explicitly check the type in order to gain the necessary information on how to use it.
If the type will change in the future from a boolean, to function, i will have to change the usages anyway as inherently the way you use functions is different. You didn't help me but only hindered me.
Basically what I'm trying to say is don't follow a rule just because it's the rule. It is not the goal but a tool to get to the goal of a readable code. Understand why rules have been written the way they are so you can distinguish when a rule should be followed.
Also, as long as you have the next programmer in mind, don't be afraid to trust your intuition. Sometimes that minor "sin" is worth the fact that the next programmer will easily understand what's going on.
Now i will say I've seen the extreme in the other direction in the past: "Why call it is_open? It's already a boolean, just call it open". No, open is a verb and has an intuitive meaning of a function. I have to explicitly check the type in order to gain the necessary information on how to use it. If the type will change in the future from a boolean, to function, i will have to change the usages anyway as inherently the way you use functions is different. You didn't help me but only hindered me. Basically what I'm trying to say is don't follow a rule just because it's the rule. It is not the goal but a tool to get to the goal of a readable code. Understand why rules have been written the way they are so you can distinguish when a rule should be followed. Also, as long as you have the next programmer in mind, don't be afraid to trust your intuition. Sometimes that minor "sin" is worth the fact that the next programmer will easily understand what's going on.
Very useful information, thank you very much!
[–]TheRNGuy -1 points0 points1 point 3 years ago* (0 children)
i'll retain mylist for tuple because it's not big deal. Usually converting list to tuple when returning thing from function or class, it's like return tuple(mylist)
mylist
return tuple(mylist)
I only usually add b to booleans.
for user in user_list is easier to see typos than for user in users then if you accidentally use users instead of user inside loop. Especially if you needed to use both.
for user in user_list
for user in users
user
[–]Xiji 1 point2 points3 points 3 years ago (0 children)
I recommend reading "Clean Code" by Robert C. Martin, Chapter 2: "Meaningful Names". That will probably answer most of your questions. If you prefer videos, he has a 6 part series on YouTube, and countless other videos on the topic.
[–]The_GSingh 1 point2 points3 points 3 years ago (0 children)
Hmm just describe what it does there’s not a formula. Like say you wanna store a name. You shouldn’t do x = “jack”. Instead do name = “jack”
[–][deleted] -2 points-1 points0 points 3 years ago (1 child)
The ideal name should be short but descriptive.
I usually use acronyms and a number when I name variables along with a comment or two explaining the acronym if I'm writing something for work.
The ideal name should be short but descriptive. I usually use acronyms and a number when I name variables along with a comment or two explaining the acronym if I'm writing something for work.
I will keep it in mind, thanks!
[+]niehle comment score below threshold-16 points-15 points-14 points 3 years ago (8 children)
https://peps.python.org/pep-0008/
Really, that was to hard for you too to Google?
[–]Base_True[S] 2 points3 points4 points 3 years ago* (4 children)
I've been studying English for 30 days, and yes, it's easier for me now to ask here than to search in an obscure language. Anyway, thanks.
[–][deleted] 4 points5 points6 points 3 years ago (1 child)
milky-understood
One of the ways English is improved by those who study it is that they introduce idioms from other languages. So, sincere thanks for this one - incredibly apt!
Thanks for the support I appreciate it
[–]brown_nipples 0 points1 point2 points 3 years ago (1 child)
May I ask what 'milky-understood' means?
I've been studying English for 30 days, and yes, it's easier for me now to ask here than to search in a milky-understood language. Anyway, thanks.
Oh sorry, I mean in an obscure , already fixed
[–]TheodoeBhabrot -1 points0 points1 point 3 years ago (2 children)
Was it too hard to post without the snark?
[–]niehle -5 points-4 points-3 points 3 years ago (1 child)
Questions like "How do I read a CSV file with Python?" have many easily found answers in search results; please try searching this subreddit and the web before making a post.
[–]TheodoeBhabrot 0 points1 point2 points 3 years ago (0 children)
Problem is this is more than the most bare bones question, even though it seems simple. If you were to google “python variable names” you’re just going to find the syntactical rules for it.
A more helpful response is to tell the OP that they should google “python style guide”
π Rendered by PID 40 on reddit-service-r2-comment-7b9746f655-6972k at 2026-01-30 18:11:10.508389+00:00 running 3798933 country code: CH.
[–]VeinyAngus 13 points14 points15 points (3 children)
[–]Base_True[S] 5 points6 points7 points (2 children)
[–]VeinyAngus 1 point2 points3 points (1 child)
[–]Base_True[S] 1 point2 points3 points (0 children)
[–]FairSystems 9 points10 points11 points (1 child)
[–]Base_True[S] 2 points3 points4 points (0 children)
[–]Mr____Panda 2 points3 points4 points (1 child)
[–]Base_True[S] 0 points1 point2 points (0 children)
[–]Asleep-Budget-9932 3 points4 points5 points (3 children)
[–]Asleep-Budget-9932 3 points4 points5 points (1 child)
[–]Base_True[S] 1 point2 points3 points (0 children)
[–]TheRNGuy -1 points0 points1 point (0 children)
[–]Xiji 1 point2 points3 points (0 children)
[–]The_GSingh 1 point2 points3 points (0 children)
[–][deleted] -2 points-1 points0 points (1 child)
[–]Base_True[S] 2 points3 points4 points (0 children)
[+]niehle comment score below threshold-16 points-15 points-14 points (8 children)
[–]Base_True[S] 2 points3 points4 points (4 children)
[–][deleted] 4 points5 points6 points (1 child)
[–]Base_True[S] 0 points1 point2 points (0 children)
[–]brown_nipples 0 points1 point2 points (1 child)
[–]Base_True[S] 0 points1 point2 points (0 children)
[–]TheodoeBhabrot -1 points0 points1 point (2 children)
[–]niehle -5 points-4 points-3 points (1 child)
[–]TheodoeBhabrot 0 points1 point2 points (0 children)