Created
July 5, 2024 16:12
-
-
Save 2tony2/c9c3d045f1663fbcb548b6d79e7921d3 to your computer and use it in GitHub Desktop.
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 count_up_to(max): | |
count = 1 | |
while count <= max: | |
yield count | |
count += 1 | |
counter = count_up_to(3) | |
print(next(counter)) # Output: 1 | |
print(next(counter)) # Output: 2 | |
print(next(counter)) # Output: 3 | |
# Calling next again will raise StopIteration |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment