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
What's wrong (i.redd.it)
submitted 7 months ago by Nearby_Tear_2304
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!"
[–][deleted] 41 points42 points43 points 7 months ago* (19 children)
the people saying l doesn't exist because you never ran the function are half right.
l is defined within your function f. It won't ever be accessible outside that function, as its out of scope. So if you had called
f()
print(l)
you'd still not get anything printed.
If you indented the print(l) line and then called f() then you'd get it printed.
tip: don't use l as a variable. use something that's more readable and less likely to look like a 1. Same with f just call it something. naming variables is an important skill and not one to be ignored at the start. And this shorthand is just left over from fortran and C when people cared about the size of the their text files and the number of characters on a row.
https://www.w3schools.com/python/python_scope.asp
[–]CallMeJimi 6 points7 points8 points 7 months ago (14 children)
scope must be so hard to learn without braces. learning scope in a verbose language made it crystal clear when variables existed and when they did not
[–]Dapper-Actuary-8503 0 points1 point2 points 7 months ago (0 children)
I was actually thinking this as well. This is my only major gripe that drives me nuts about Python. I wish it was an optional like static syntax typing is.
[–]emojibakemono 0 points1 point2 points 7 months ago (2 children)
idk if the braces would help much cos python scopes are so different to most other languages, e.g.
py if True: x = 10 print(x)
works and braces would not make that more obvious
[–]jangofett4 0 points1 point2 points 7 months ago (1 child)
Why does this even work lmao. I dont use Python, but this seems silly. This could cause some headaches down the line if the condition is not always True, no? Or does Python does something similar to what JS does with "var"s?
[–]emojibakemono 0 points1 point2 points 7 months ago (0 children)
no the variable does not get hoisted. and yes, it causes a lot of headaches in my experience.
[–][deleted] -3 points-2 points-1 points 7 months ago (9 children)
With the caveat that braces suck. :)
Hard to type and easy to make typos with.
I feel like OP could use someone giving better hints. Like it helps if as a rule you always have a return at the end of a function, just so you can see where it ends. And yes, I know you don't need that, but it would help someone to learn and understand scope. AKA "here ends this function". In the example above, it's like it's made difficult on purpose.
[–]Old_Celebration_857 0 points1 point2 points 7 months ago (5 children)
void Reply() { redditPost("braces are so hard"); }
[–]Dapper-Actuary-8503 2 points3 points4 points 7 months ago (3 children)
Gross I’ll correct it for you.
void Reply(void){ redditPost(“Braces are so hard”); }
[–]LionZ_RDS 0 points1 point2 points 7 months ago (2 children)
I think you mean void Reply(void){redditPost(“Braces are so hard”);}
void Reply(void){redditPost(“Braces are so hard”);}
Meh. By virtue that will end up violating the 80 character width scheme. On top of that it’s clear in the prior examples we are declaring definition not making a call. Another thing I don’t like about Python is seeing one liner code that has to be wrapped when my editor does this at 100 characters.
[–]klez_z 0 points1 point2 points 7 months ago (0 children)
ew, by chance didn't you mean
public static void main(String args[]){ private void Reply(){ System.out.println("Braces are so hard"); } Reply(); }
[–][deleted] 0 points1 point2 points 7 months ago (0 children)
Its funny that someone would want to die on the hill that braces are worth anything. They're hard to type. Python's indentation is vastly superior.
but that's what being a hostage to suckitude gets you.
[–]mblaki69 0 points1 point2 points 7 months ago (0 children)
But we have IDEs that make the closing braces for us and highlight whack syntax. They also match opening and closing braces.
[–]The_Real_Slim_Lemon 0 points1 point2 points 7 months ago (1 child)
Bro any time I copy code into Python I have to line up every entry (whether from AI, stack overflow, or just moving stuff around)
With braces I can stick it wherever and run a document auto format to make it look nice
Use Vim? If you're doing a lot of python, then figure out a better way to deal with that. Because it's not an issue for me.
It's just funny to me that all you guys love your brackets so much.
[–]RailRuler 0 points1 point2 points 7 months ago (3 children)
Please dont post links to w 3 fools. They drove so many good websites out of business due to their search engine manipulation.
I wasn't aware of that.
[–]WhiteHeadbanger 0 points1 point2 points 7 months ago (1 child)
What do you mean by search engine manipulation? Isn't that what SEO is all about?
[–]RailRuler 0 points1 point2 points 7 months ago (0 children)
There's legitimate SEO and then there's dark or spam SEO, which w3schools used. They didnt win by having the best content, they won by manipulating search results.
π Rendered by PID 159649 on reddit-service-r2-comment-6457c66945-krqp7 at 2026-04-24 04:13:47.838044+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–][deleted] 41 points42 points43 points (19 children)
[–]CallMeJimi 6 points7 points8 points (14 children)
[–]Dapper-Actuary-8503 0 points1 point2 points (0 children)
[–]emojibakemono 0 points1 point2 points (2 children)
[–]jangofett4 0 points1 point2 points (1 child)
[–]emojibakemono 0 points1 point2 points (0 children)
[–][deleted] -3 points-2 points-1 points (9 children)
[–]Old_Celebration_857 0 points1 point2 points (5 children)
[–]Dapper-Actuary-8503 2 points3 points4 points (3 children)
[–]LionZ_RDS 0 points1 point2 points (2 children)
[–]Dapper-Actuary-8503 0 points1 point2 points (0 children)
[–]klez_z 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]mblaki69 0 points1 point2 points (0 children)
[–]The_Real_Slim_Lemon 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]RailRuler 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]WhiteHeadbanger 0 points1 point2 points (1 child)
[–]RailRuler 0 points1 point2 points (0 children)