Created
October 11, 2018 16:37
-
-
Save ebertti/49bf09297ba346e80cf9909fd4be7cb9 to your computer and use it in GitHub Desktop.
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
# antes de executar este código, tente adivinhar a ordem dos prints em cada cenário | |
def gerador(qtd): | |
print('10 antes') | |
for i in range(qtd): | |
print('20 para cada', i) | |
yield i * 10 | |
def normal(qtd): | |
print('10 antes') | |
lista = [] | |
for i in range(qtd): | |
print('20 para cada', i) | |
lista.append(i * 10) | |
return lista | |
if __name__ == '__main__': | |
print('1 main') | |
l = normal(2) | |
#l = gerador(2) | |
print('2 depois do init') | |
for i in l: | |
print('3 fora', i) | |
# troque entre normal(2) e gerador(2) para ver a diferença |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment