+ 1
The colon
Am I correct in assuming that the colon acts as a tie in with the first statement? There is a colon after the 5 perhaps indicating it may contain additional conditions and the colon after the else statement ties that else to the first if. Yes?
4 Respuestas
+ 3
Sounds like you might be referring to Python, but I am not sure... is there some code that you can share to help illustrate your point? It would be easier to see what you are referring to in order to provide an accurate answer.
+ 2
My apologies, of course. This is in the Python set of instructions and here is the code they are presenting:
x = 4
if x == 5:
print("Yes")
else:
print("No")
+ 2
Ok yeah, the colon separates the code blocks. So everything that is indented beneath the colon, belongs to the colon above it.
if x==5:
print("Yes") #belongs to the if statement
else:
print("No") #belongs to the else statement
Python uses indentations to separate code blocks in a parent/child-like relationship. With conditional statements like this, you can have an "if" and not have an "else". However, you cannot have an "else" without an "if". I hope that makes sense.
+ 2
It does. I appreciate your time. Thank you.