What does multiple variables mean in Python 'for loop' ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

What does multiple variables mean in Python 'for loop' ?

I saw this 'for loop' in a code somewhere, I wonder what it is and how it works. It has 4 variables in parenthesis, usually I've seen and used only one variable which iterates through a list or a range. for (x, y, w, h) in faces:

6th Sep 2019, 4:36 PM
Tanish Kushwaha
Tanish Kushwaha - avatar
2 Answers
+ 9
you can see it like this: nums = [[1,2,3,4],[5,6,7,8]] for (a,b,c,d) in nums: #for a,b,c,d in nums: # it can be used with or without parenthesis print(a,b,c,d) # output: ''' 1 2 3 4 5 6 7 8 ''' so the sub-lists in nums will be splitted to individual variables a, b, c, d.
6th Sep 2019, 4:45 PM
Lothar
Lothar - avatar