我正在尝试编写一段代码,想请问如何让while循环重复执行直到找到列表中的一个单词,例如我的情况是END。
L=[]
while "END" (not) in L :
L=L.append(something)
如果您不理解我的意思,请问我。
L=[]
while "END" (not) in L :
L=L.append(something)
如果您不理解我的意思,请问我。
您的代码按照原样将正常运行,除非list.append()
返回None,并在原地修改列表; 不要将其分配回L:
L=[]
while "END" not in L :
L.append(something)
>>> a = [1,2,3]
>>> while 12 not in a:
... a.append(len(a)+1)
...
>>> a
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
For example ...
for something in somethings:
if something != "END":
L.append(something)
END
突然出现在L
中?something
来自哪里? - user647772