Difference between revisions of "Python:Control structures"
Jump to navigation
Jump to search
(Created page with "Category:Python To catch all exceptions (not wise) ==Exception handling== <syntaxhighlight lang=python> try: block except: blockifexceptionisthrown </syntaxhighli...") |
|||
Line 1: | Line 1: | ||
[[Category:Python]] | [[Category:Python]] | ||
+ | Most flow control is standard. Indentation defines the code block to execute. You must be strich, all indents must be the same in a block, amix of spaces and tab is not allowed (unless each line uses the same mix).......... | ||
+ | |||
+ | <syntaxhighlight lang=python> | ||
+ | if expression: | ||
+ | block | ||
+ | else: | ||
+ | otherblock | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | ;<code>pass</code> | ||
+ | :No operation, use e.g. to avoid negative tests | ||
+ | |||
+ | ==Exception handling== | ||
To catch all exceptions (not wise) | To catch all exceptions (not wise) | ||
− | |||
<syntaxhighlight lang=python> | <syntaxhighlight lang=python> | ||
try: | try: |
Revision as of 21:31, 2 May 2018
Most flow control is standard. Indentation defines the code block to execute. You must be strich, all indents must be the same in a block, amix of spaces and tab 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