This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
notes:python_cheat_sheet [2026/11/02 00:44] 108.246.45.155 old revision restored (2026/10/27 12:01) |
notes:python_cheat_sheet [2026/11/03 03:29] (current) 101.166.17.61 old revision restored (2026/08/03 07:52) |
||
|---|---|---|---|
| Line 108: | Line 108: | ||
| * Syntax errors are parsing errors, exceptions are runtime errors. | * Syntax errors are parsing errors, exceptions are runtime errors. | ||
| * Exceptions are class objects in the exceptions module. [[http:// | * Exceptions are class objects in the exceptions module. [[http:// | ||
| - | * Exception handling is supported using try..except..else..finally :<code python> | + | * Exception handling is supported using try..except..else..finally : |
| + | <code python> | ||
| try: | try: | ||
| - | | + | result = x / y |
| except ZeroDivisionError: | except ZeroDivisionError: | ||
| - | | + | print(" |
| except Exception as inst: | except Exception as inst: | ||
| - | | + | print(type(inst)) |
| - | print(inst.args) | + | |
| - | print(inst) | + | |
| else: | else: | ||
| - | | + | print(" |
| finally: | finally: | ||
| - | | + | print(" |
| - | </ | + | |
| - | * Errors can be raised using '' | + | |
| - | * New exception classes can be created and should derive from the Exception class. | + | |
| - | * '' | + | |
| - | with open(" | + | |
| - | for line in f: | + | |
| - | print(line) | + | |
| </ | </ | ||
| + | * Errors can be raised using <code python> | ||
| + | * | ||