添加一个
break声明中
if,当串中发现的块,然后移动
else是
elsefor循环。如果在这种情况下找到了字符串,则循环将中断并且永远不会到达else,如果循环没有制动,则将达到else并被
'Stringnot found'打印。
for i in animals: if 'cat' in i: print('String found') breakelse: print('String not found')
添加一个
break声明中
if,当串中发现的块,然后移动
else是
elsefor循环。如果在这种情况下找到了字符串,则循环将中断并且永远不会到达else,如果循环没有制动,则将达到else并被
'Stringnot found'打印。
for i in animals: if 'cat' in i: print('String found') breakelse: print('String not found')