str1='hello123' for x in str1: if x=='l': continue #跳出本次循环 print(x, end='') #else: #print(x,end='') print() for x in str1: if x=='l': break #跳出整体循环 print(x, end='') #else: #print(x,end='') print() for x in str1: #print(x,end='') if x=='l': pass #占位语句,不做任何操作,为了保持程序的完整性 print(x, end='') #else: #print(x,end='') print()
运行结果
C:UserschenyuAppDataLocalProgramsPythonPython37python.exe G:/测码/python-03-进阶/__init__.py heo123 he hello123 Process finished with exit code 0