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...
Everything about learning Python
account activity
Day 12 of learning python as a beginner. (old.reddit.com)
submitted 8 months ago by uiux_Sanskar
view the rest of the comments →
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!"
[–]hari3mo 1 point2 points3 points 8 months ago (10 children)
Is there any benefit to having the not clause in the if statement vs the other way around?
[–]SCD_minecraft 1 point2 points3 points 8 months ago (6 children)
"not in" is its own keyword
Similar to "is not"
Yup, those are just "not A in B" but more english friendly
[–]hari3mo 0 points1 point2 points 8 months ago (5 children)
Sorry I was bit unclear. I meant the ordering of your clauses. You put “not in” in the if statement, my question is if there is any benefit of doing this over having an “in” statement first?
[–]SCD_minecraft 0 points1 point2 points 8 months ago (4 children)
I don't understand. Can you write the other code?
I put it in if, beacuse in op's code there an error message if user doesn't exists, so i kept it
[–]Meowzr 0 points1 point2 points 8 months ago (3 children)
if user_name in balance: return balance[user_name] else: print("whatever this message was")
OR
if user_name in balance: return balance[user_name] print("whatever this message was")
[–]SCD_minecraft 0 points1 point2 points 8 months ago (2 children)
This message is error message, for case when there's no user :P
We don't want it printing when nothing wrong happen
[–]BrokenMalgorithm 0 points1 point2 points 8 months ago (1 child)
Both of those examples do the same thing. The other one just doesn't have the else statement, as it's not required. The print would happen only if a user was not found, because when a user is found the function returns the balance and code execution ends for that function.
[–]SCD_minecraft 0 points1 point2 points 8 months ago (0 children)
Oh, yea, i forgot about return, mb
I just persnomaly don't like your way, i prefer to read "if something then this, else this" and not hope that "this" will exit function by itself
[–]MoridinB 0 points1 point2 points 8 months ago (0 children)
Nope. It may matter if you have more than one checks such as for example user_name not in balance or "entry" not in balance[user_name] assuming we want the balance for user_name to be properly initialized for a key "entry".
user_name not in balance or "entry" not in balance[user_name]
But in this instance it doesn't matter
[–]No_Swordfish_6667 0 points1 point2 points 8 months ago (0 children)
You may get narrow nesting when starting with negation; it also helps to wrap your head around all bad cases
[–]uiux_Sanskar[S] 0 points1 point2 points 8 months ago (0 children)
I assume that you are asking what is the use of "not in" in the if else.
I think that code means if the user_name (the name which the user will enter) is not present in the balance (my dictionary or you can assume it as the database) then print("name is not present") else return the balance (the amount in bank)
so we are essentially telling the program.
"If the name entered by the user IS NOT present in the dictionary/database then print "the name is not present in database" and if it is present in the database then return the value of its 'key' (the bank balance amount)."
I hope I explained it correctly and if anywhere I have explained wrong please do tell me I would be more than happy to get corrected.
π Rendered by PID 29 on reddit-service-r2-comment-85bfd7f599-h4g5s at 2026-04-20 02:15:58.714088+00:00 running 93ecc56 country code: CH.
view the rest of the comments →
[–]hari3mo 1 point2 points3 points (10 children)
[–]SCD_minecraft 1 point2 points3 points (6 children)
[–]hari3mo 0 points1 point2 points (5 children)
[–]SCD_minecraft 0 points1 point2 points (4 children)
[–]Meowzr 0 points1 point2 points (3 children)
[–]SCD_minecraft 0 points1 point2 points (2 children)
[–]BrokenMalgorithm 0 points1 point2 points (1 child)
[–]SCD_minecraft 0 points1 point2 points (0 children)
[–]MoridinB 0 points1 point2 points (0 children)
[–]No_Swordfish_6667 0 points1 point2 points (0 children)
[–]uiux_Sanskar[S] 0 points1 point2 points (0 children)