#๐ if else
41 messages ยท Page 1 of 1 (latest)
@dull tusk
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
neither, as the indentations don't align
the else is indented on the same level as if i in marked:
yes .. i wanted to make sure
in C , this would cause a dangling if else problem
so if k==3 : does not affect the else right
right
but theres a problem
what problem?
for...else means something else
the else is executed if there is no break statement executed within the for loop
so it runs unless you break out of the for loop
:x: Your 3.12 eval job has completed with return code 1.
001 | File "/home/main.py", line 3
002 | else:
003 | ^^^^
004 | SyntaxError: invalid syntax
your else is not aligned with the for
OHH i thought here it was for the original for
!e
for i in range(5):
print(1)
else:
print(2)
print("hello")
:white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | 1
002 | 1
003 | 1
004 | 1
005 | 1
006 | 2
007 | hello
I use it when my for loop searches for a matching item in an iterable, and doesn't find it
if a match is found, I break out of the loop early
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.