欢迎关注小睿的微信公众号:郭小睿同学
,每天更新小知识、笔记、案例、学习资源~
import sys
while True:
print("Type exit to exit.")
response = input()
if response == "exit":
sys.exit()
print("You typed " + response + ".")
用户输入exit,导致程序sys.exit()被调用。如果response等于exit,则程序就会中止。