小编Koo*_*vet的帖子

如何使 for 循环使用由 if 语句创建的新列表

这是我的代码:

the_list = ['Lily', 'Brad', 'Fatima', 'Zining']

for name in the_list:
    print(name)
    if name == 'Brad':
      the_list = ['Tom', 'Jim', 'Garry', 'Steve']
    else:
      continue

Run Code Online (Sandbox Code Playgroud)

如何使 for 循环现在通过新列表运行

我知道我可以在 if 语句中创建一个新的 for 循环,但这不是我想要的。

python for-loop if-statement nested list

2
推荐指数
1
解决办法
31
查看次数

标签 统计

for-loop ×1

if-statement ×1

list ×1

nested ×1

python ×1