Added text on the semicolon use alongside indents (#21592)
In the section introducing and elaborating upon if and elif-statements, I made a small note on how the rest of the structure is just as crucial, particularly, the semicolon. That is because, while this file is on indentation, it also regards the structural requirements of a code and how to be refrain from avoidable errors. The same way you can easily avoid an error by remembering when to properly indent is seen when we remember to always include a semicolon after a condition.
This commit is contained in:
committed by
Manish Giri
parent
96ffe31186
commit
4b701255b9
@ -39,7 +39,9 @@ else:
|
||||
print('adult fare')
|
||||
```
|
||||
|
||||
After Python gets age from the user, it enters the if/elif-statement and checks each condition one after the other in the order they are given. So first it checks if age is less than 2, and if so, it indicates that the flying is free and jumps out of the elif-condition. If age is not less than 2, then it checks the next elif-condition to see if age is between 2 and 13. If so, it prints the appropriate message and jumps out of the if/elif-statement. If neither the if-condition nor the elif-condition is True, then it executes the code in the else-block.
|
||||
After Python gets age from the user, it enters the if/elif-statement and checks each condition one after the other in the order they are given. So first it checks if age is less than 2, and if so, it indicates that the flying is free and jumps out of the elif-condition. If age is not less than 2, then it checks the next elif-condition to see if age is between 2 and 13. If so, it prints the appropriate message and jumps out of the if/elif-statement. If neither the if-condition nor the elif-condition is True, then it executes the code in the else-block.
|
||||
|
||||
Along the lines of how crucial indentation is, regard how the rest of the structure may be equally important. For instance, the use of a semicolon `:` after the if- or elif-conditions indicates that the conditions to be met have all been described and allow for the actions, the next line that is further indented such as the print arguments, to be understood by Python.
|
||||
|
||||
#### Conditional expressions
|
||||
Python has one more logical operator that some programmers like (and some don’t!). It’s essentially a shorthand notation for if-statements that can be used directly within expressions. Consider this code:
|
||||
|
Reference in New Issue
Block a user