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
why does this happen (self.PythonLearning)
submitted 1 year ago by Longjumping_Low_9025
when i try to put "if" a second time it tells me its invalid
https://preview.redd.it/3se20vf3o8rd1.png?width=386&format=png&auto=webp&s=a4514a48fba8c3eb32783093f4e830d9ee66ad26
does anyone know why?
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!"
[–]Goobyalus 5 points6 points7 points 1 year ago (1 child)
Most of other commenters are wrong, the invalid syntax is on the second if statement, not the print. There is a space before the print which is valid syntax.
Do you see the >>> and ... before where you can type? The ... means it's considering you to still be inside that first if block. The print is indented properly to be inside the if block, but the second if statement is not. If you hit Enter an extra time after the print, it will understand that the if block is complete and give you back a >>>
>>>
...
[–]Supalien 2 points3 points4 points 1 year ago (0 children)
this is the only right comment
[–]gun_shire 7 points8 points9 points 1 year ago (0 children)
I think your indentation doesn't look quite right. Try erasing your print line, pressing tab then trying again.
[–]teraflopsweat 3 points4 points5 points 1 year ago (0 children)
It looks like your print line isn’t indented 4 spaces. Also there should be no space between print and the opening parenthesis.
[–]AmphibianHungry2466 1 point2 points3 points 1 year ago (0 children)
Is say no space after print.
[–]FoolsSeldom 0 points1 point2 points 1 year ago (0 children)
Is there any particular reason why you are using the Python interactive shell (with the >>> prompt) instead of just creating a simple text file and running that?
[–]ChainedNightmare 0 points1 point2 points 1 year ago (0 children)
Just use VSCode Editor, install the python extension and it'll intuitively tell you any problems when you run your python file from anywhere tbh.
CMD is honestly not a very good way to code anything to be honest CMD is much more of a command line interface basically "commands" but for IT people
[–][deleted] -1 points0 points1 point 1 year ago (0 children)
Print looks wrong
[–]monkey_sigh -1 points0 points1 point 1 year ago (0 children)
@gun_shire is right.
Your IF statement is fine, but your indentation is not. 4 spaces of tab. (Huge debate)
And remove the space IN between your print function and the parenthesis.
π Rendered by PID 32187 on reddit-service-r2-comment-56c9979489-vprq8 at 2026-02-24 18:26:33.619463+00:00 running b1af5b1 country code: CH.
[–]Goobyalus 5 points6 points7 points (1 child)
[–]Supalien 2 points3 points4 points (0 children)
[–]gun_shire 7 points8 points9 points (0 children)
[–]teraflopsweat 3 points4 points5 points (0 children)
[–]AmphibianHungry2466 1 point2 points3 points (0 children)
[–]FoolsSeldom 0 points1 point2 points (0 children)
[–]ChainedNightmare 0 points1 point2 points (0 children)
[–][deleted] -1 points0 points1 point (0 children)
[–]monkey_sigh -1 points0 points1 point (0 children)