For循环For循环-Python

For循环For循环-Python,python,loops,for-loop,Python,Loops,For Loop,输出:aabcbabccabc 如何获得这样的输出?: aabbcc您可以使用zip内置功能。它将返回您传递的所有iterables的第i项。看 就你而言: l1 = ["a", "b", "c"] l2 = ["a", "b", "c"] for i in l1: print(i) for i in l2: print(i) 使用zip:

输出:
aabcbabccabc
如何获得这样的输出?:
aabbcc

您可以使用
zip
内置功能。它将返回您传递的所有iterables的第i项。看

就你而言:

l1 = ["a", "b", "c"]
l2 = ["a", "b", "c"]

for i in l1:
    print(i)
    for i in l2:
        print(i)
使用
zip

for it in zip(l1, l2):
    # the * is for extracting the items from it
    # sep="" does not print any spaces between
    # end="" does avoid printing a new line at the end
    print(*it, sep="", end="")

如果阵列大小相同,可以执行以下操作:

l1 = ["a", "b", "c"]
l2 = ["a", "b", "c"]


for a, b in zip(l1, l2):
  print(a)
  print(b)

我们可以使用下面的zip函数

for i in range((len(l1)):
    print(l1[i])
    print(l2[i])

谢谢你,亚历山大!谢谢你,罗尼。这就是我需要的
print(*(y for x in zip(l1,l2) for y in x))