+ 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?

9th Sep 2020, 3:33 PM
Timothy Reid
Timothy Reid - avatar
4 Antworten
+ 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.
9th Sep 2020, 3:43 PM
Steven M
Steven M - avatar
+ 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")
9th Sep 2020, 3:48 PM
Timothy Reid
Timothy Reid - avatar
+ 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.
9th Sep 2020, 3:58 PM
Steven M
Steven M - avatar
+ 2
It does. I appreciate your time. Thank you.
9th Sep 2020, 4:01 PM
Timothy Reid
Timothy Reid - avatar