Can I iterate or loop through the values of a function in Python like for i in function Name: statement | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Can I iterate or loop through the values of a function in Python like for i in function Name: statement

Possibility of looping through a def function using for loop

9th Apr 2021, 5:47 AM
E∆SI🇳🇬🤖
E∆SI🇳🇬🤖 - avatar
4 Answers
+ 2
Yes with generator. Like this def gen(n): for i in range(n): yield i for i in gen(6): print(i)
9th Apr 2021, 5:52 AM
TOLUENE
TOLUENE - avatar
+ 1
Yes, when the function returns an iterable (e.g. list, tuple, set, dictionary, generator, string)
9th Apr 2021, 8:30 AM
Benjamin Jürgens
Benjamin Jürgens - avatar
14th Apr 2021, 9:45 AM
E∆SI🇳🇬🤖
E∆SI🇳🇬🤖 - avatar
+ 1
Benjamin Jürgens thanks exactly. Those are the types am trying to iterate
14th Apr 2021, 9:46 AM
E∆SI🇳🇬🤖
E∆SI🇳🇬🤖 - avatar