我是编码初学者 请让我知道如何为以下内容在python中编写for循环语句。
a = ['I' ,'U']
b = ['play', 'like']
c = ['piano' , 'violin']
所以现在如何使用for循环打印语句如下---
I like piano
U like piano
I play piano
U play piano
I like violin
U like violin
I play violin
U play violin
谢谢!
答案 0 :(得分:1)
您需要嵌套循环。您还需要反转b数组。
a = ['I' ,'U']
b = ['play', 'like']
c = ['piano' , 'violin']
b.reverse()
for i in c:
for j in b:
for k in a:
print(k+" "+j+" "+i)