flâneur — a map of the web's best reading

4. More Control Flow Tools — Python 3.12.2 documentation

docs.python.org · 7,021 words · saved by 1 readers

As well as the while statement just introduced, Python uses a few more that we will encounter in this chapter. Perhaps the most well-known statement type is the if statement. For example: There can be zero or more elif parts, and the else part is optional. The keyword ‘elif’ is short for ‘else if’, and is useful to avoid excessive indentation. An if … elif … elif … sequence is a substitute for the switch or case statements found in other languages. If you’re comparing the same value to several constants, or checking for specific types or attributes, you may also find the match statement useful. For more details see match Statements. The for statement in Python differs a bit from what you may be used to in C or Pascal. Rather than always iterating over an arithmetic progression of numbers (like in Pascal), or giving the user the ability to define both the iteration step and halting condition (as C), Python’s for statement iterates over the items of any sequence (a list or a string), in

4. More Control Flow Tools &#8212; Python 3.14.6 documentation Navigation index modules | next | previous | Python &#187; 3.14.6 Documentation &#187; The Python Tutorial &#187; 4. More Control Flow Tools | Theme Auto Light Dark | 4. More Control Flow Tools ¶ As well as the while statement just introduced, Python uses a few more that we will encounter in this chapter. 4.1. if Statements ¶ Perhaps the most well-known statement type is the if statement. For example: >>> x = int ( input ( "Please enter an integer: " )) Please enter an integer: 42 >>> if x < 0 : ... x = 0 ... print ( 'Negative chan

Explore this link on the map →

related reading