python之break、continue、exit及实现命令行提示符
break:跳出整个循环,不会再循环后面的内容
continue:跳出本次循环,continue后面的代码不再执行,但是循环依然继续
eixt( ):结束程序的下运行
for i in range(10):
if i == 5:
#break
#continue
exit()
print(i)
print('hello')
break
continue
exit()
实现命令行提示符
import os
for i in range(1000):
cmd = input('[[email protected] ~]# ')
if cmd:
if cmd == 'exit':
print('logout')
break
else:
print('run %s' %(cmd))
# 运行shell命令
os.system(cmd)
else:
continue