Quick actions

cmd+k|ctrl+k

Navigation

Languages

Lecture 8_Try & except

Snippet info

Language

Python

Visibility

public

Author

natlyy0816

Created

2024-12-04T12:55:29.172887Z

Updated

2024-12-04T12:55:29.172887Z

try: ###如果無try就行唔到
    x=1/0
except ZeroDivisionError: ##直接做一次error message再paste
     print('zero division error')
else:
    print("data is ok")
#####################################################    
try:
    x=1/2
except TypeError: #直接做一次error message再paste
     print('make sure your input type is right')
except ZeroDivisionError: 
     print('zero division error')
else:
    print("data is ok")
finally:
    print("file closed")
INFO