Home > OS >  For loop with different variables python
For loop with different variables python

Time:07-24

Lets say i have three arrays :

listXYZ = ['X','Y', 'Z']
list123 = ['1','2','3']
listLetter= ['FF','GG','ZZ']

I tried

for list,x,y in listXYZ,list123,listLetter:
print(list,x,y)

and im getting output x,y,z 1,2,3 etc . What i want is for it to print X 1 FF, Y 2 GG etc. How do i do that ?

CodePudding user response:

You can use zip() like so:

for x, y, z in zip(listXYZ,list123,listLetter):
    print(x, y, z)

Also please don't use builtin names as variable names.

  • Related