Python:Control structures: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
mNo edit summary |
||
| Line 1: | Line 1: | ||
[[Category:Python]] | [[Category:Python]] | ||
Most flow control is standard. Indentation defines the code block to execute. You must be | Most flow control is standard. Indentation defines the code block to execute. You must be strict, all indents must be the same in a block, a mix of spaces and tabs is not allowed (unless each line uses the same mix).......... | ||
<syntaxhighlight lang=python> | <syntaxhighlight lang=python> | ||
Revision as of 07:31, 17 July 2018
Most flow control is standard. Indentation defines the code block to execute. You must be strict, all indents must be the same in a block, a mix of spaces and tabs is not allowed (unless each line uses the same mix)..........
if expression:
block
else:
otherblock
pass- No operation, use e.g. to avoid negative tests
Exception handling
To catch all exceptions (not wise)
try:
block
except:
blockifexceptionisthrown
You better only catch the exceptions you expect. You can choose from the available exceptions [1]
- except NameError
- The variable does not exist