This file contains hidden or 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
list_comprehension = [1,2,3,4,5,6,7,8] |
This file contains hidden or 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
>>> for item in generator(): | |
... print(item) | |
... | |
Essa é uma função Generator | |
1 | |
2 | |
3 | |
>> |
This file contains hidden or 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
>>> # Quando a função termina, a exceção StopIteration é levantada automaticamente. | |
>>> next(a) | |
Traceback (most recent call last): | |
... | |
StopIteration | |
>>> next(a) | |
Traceback (most recent call last): | |
... | |
StopIteration |
This file contains hidden or 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 generator(): | |
n = 1 | |
print("Essa uma função Generator") | |
yield n | |
n += 1 | |
yield n | |
n += 1 | |
yield n |
NewerOlder