+ 7
Usually the full if statement block is like this: some_code if condition1: block1 elif condition2: block2 elif condition3: block3 else: blockx rest_of_code In Python, if statements are exclusive, i.e. only one of those blocks above gets executed. And it is the first one which will prove to be True. If condition1 is True, the block1 gets executed and when it's done, the interpreter goes directly to rest_of_code part. If condition1 is False, *only then* the condition2 is checked. If it is True, block2 gets executed and the if statement is exited (goes to rest_of_code right away). And so on... If all conditions are False, *only then* the else part gets executed (if present, because it is not compulsory). Of course, after this the interpreter goes to rest_of_code :)
3rd Jul 2017, 10:18 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar