def func(): list = [] usr = input('username:') pwd = input('password:') try: list[4] # 这个是调用不了的,因为列表没有元素 except Exception as e: print(e.__class__) func()
username:11
password:1
<class 'IndexError'>
def func(): list = [] usr = input('username:') pwd = input('password:') try: name # 这个变量是没法收到的 except Exception as e: print(e.__class__) func()
username:1
password:1
<class 'NameError'>