Python 嵌套循环
循环内部的循环
嵌套循环是循环内部的循环。
"内循环" 将在 "外循环" 的每次迭代时执行一次
示例
为每个水果打印每个形容词
adj = ["red", "big", "tasty"]
fruits = ["apple", "banana", "cherry"]
for x in adj
for y in fruits
print(x, y)
自己动手试一试 »
嵌套循环是循环内部的循环。
"内循环" 将在 "外循环" 的每次迭代时执行一次
为每个水果打印每个形容词
adj = ["red", "big", "tasty"]
fruits = ["apple", "banana", "cherry"]
for x in adj
for y in fruits
print(x, y)
自己动手试一试 »
如果您想将 W3Schools 服务用于教育机构、团队或企业,请发送电子邮件给我们
sales@w3schools.com
如果您想报告错误,或想提出建议,请发送电子邮件给我们
help@w3schools.com