I didn't understand for and in | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I didn't understand for and in

Help me i didn't understand for and in :/

22nd Nov 2018, 12:42 PM
ANTIDOTE
ANTIDOTE - avatar
3 Answers
+ 1
for in loop, is used to iterate through the elements of an object. Example: Say you want to circle through the elements of a list and print their squares. nums = [2, 4, 1, 8, 7] for num in nums: print(nums**2) Output ======== 4 16 1 64 49 On the first iteration of the loop, the variable "num" is given the value 2, it then prints out 2², which is 4. On the second iteration of the loop, the variable "num" is given the value "4" it then prints out 4² which is 16. The loop goes on like that doing the same thing for every element in the list.
22nd Nov 2018, 1:14 PM
Dlite
Dlite - avatar
22nd Nov 2018, 4:33 PM
Maninder $ingh
Maninder $ingh - avatar
+ 1
thank's a lot bros
22nd Nov 2018, 8:37 PM
ANTIDOTE
ANTIDOTE - avatar