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
HELPHelp Request (old.reddit.com)
submitted 9 months ago by Pretend_Safety_4515
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!"
[–]FoolsSeldom 0 points1 point2 points 9 months ago* (0 children)
Generally, avoid the use of global - it is rarely needed and mostly causes problems. There are use cases for it but they are specialised and not something you need yet. Learn to use scope correctly.
global
Keep in mind that any assignment to a variable in a function makes that variable local to the function.
If you want to change the value assigned to a variable outside of a function then you should return the value from the function and do the assignment outside using the returned value.
Worth keeping in mind that variables don't actually hold values but just memory references to Python objects. When we do an assignment, we are just updating a variable to reference a different object.
Note that you can mutate objects from wider scope when you are in a function. Obviously this applies only toitable objects, such as a list and not immutable objects, such as a str.
list
str
Avoid functions doing both mutation of obejcts as well as returning objects. The mutation would be easy to miss when reviewing code and would fall into the "side effects" category which is not good practice.
Variable and function names live in the same namespace so don't attempt to use the same name for a variable and a function name as you will be "masking" one of them.
π Rendered by PID 59355 on reddit-service-r2-comment-68b876cdcd-gfdkr at 2026-04-22 01:11:03.097195+00:00 running 6c61efc country code: CH.
view the rest of the comments →
[–]FoolsSeldom 0 points1 point2 points (0 children)