Python: Selection - If-else Basic selection statement ...
Python: Selection - If-else ? Basic selection statement ? Simplest form syntax:
? Schematically: if Boolean expression: block else: block
? Semantics: ? if Booleanexpression is true, execute block after if ? if Booleanexpression is false, execute block following else: if the else: is included
1
Python: Selection - If-else Blocks ? Python blocks
? A block is a sequence of statements that are part of a control structure ? Syntax:
? Blocks are delimited solely by indentation ? Every statement in a block must be indented by the same amount
This is why it's so important that statements at the top level have no leading white space
? The only thing that is important is that every statement in a block has exactly the same amount of leading white space Four spaces is the usual convention Do not mix and match spaces and tabs!
? Note that the blocks must be indented more than the if and else, and that the if and else must have the same indentation
2
Python: Selection - If-else Examples ? Simple if:
pay = hours * rate if hours > 40:
pay = pay + (hours - 40) * rate * 0.5 print("Pay =", pay) ? Simple if-else example: if hours ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- conditional looping constructs
- basic python programming for loops and reading files
- working with functions in python
- learning the pythonic way
- exploring data using python 3 dr charles r severance
- introduction to python programming course notes
- python 3 tutorialspoint
- python programming 1 variables loops and
- python selection if else basic selection statement
- lecture 5 hypothesis testing in multiple linear regression