到目前为止,我有一个while循环,但我想知道如何在for循环中检查某些内容。
到目前为止我看到的是这样的:
i = 0
found = False
while ((i < len(my_string)) and (not found))
my_char = my_string[i]
if my_char in my_set:
found = True
elif my_char == 'x':
i = helper_function(my_string, i)
else:
i += 1
return i
答案 0 :(得分:0)
不确定帮助函数正在做什么,但这将是for循环看起来的基本要点
i = 0
for char in my_string:
if my_char in my_set:
break
elif my_char == 'x':
i = helper_function(my_string, i)
else:
i += 1
else:
pass ## put logic here if you need the code to do something if the char wasn't found
return i