简单的异常处理

2022-07-14 13:42:02 浏览数 (1)

# 简单的异常处理

# 代码

代码语言:javascript复制
try:
    text = input('Enter someting -->')
except EOFError:   # 按ctrl D
    print('Why did you do an EOF on me?')
except KeyboardInterrupt: # 按ctrl C
    print('You cancelled the operation.')
else:
    print('You enterd {}'.format(text))

# 运行结果

代码语言:javascript复制
Enter someting -->^D
Why did you do an EOF on me?

0 人点赞