Created
July 15, 2021 15:25
-
-
Save Mulperi/11d1118b01e0d159d8d1e6682851f804 to your computer and use it in GitHub Desktop.
Python generator example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def square_numbers(nums): | |
for i in nums: | |
yield(i*i) | |
mynums = square_numbers([1,2,3]) | |
for num in mynums: | |
print(num) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment