python 中 if语句条件判断退出,并输出错误信息
python 中 if语句条件判断退出,并输出错误信息
001、
(base) [root@PC1 test]# cat test.py ## 测试程序 #!/usr/bin/env python # -*- coding:utf-8 -*- import sys list1 = [3, 8, 30, 4] for i in list1: if i < 20: print(i) else: print("error! less than 20") sys.exit(1) (base) [root@PC1 test]# python test.py ## 运行程序,条件判断并退出 3 8 error! less than 20
。