+ 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