-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeneradores.py
More file actions
35 lines (24 loc) · 816 Bytes
/
generadores.py
File metadata and controls
35 lines (24 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""def generaPares(limite):
num=1
miLista=[]
while num<limite:
miLista.append(num*2)
num=num+1
return miLista
print(generaPares(10))"""
#queremos imprimir los pirmeros 3 elementos
#USO DE GENERADORES
def generaPares(limite):
num=1
while num<limite:
yield num*2#yield construye un objeto iterable
num=num+1
devuelPares=generaPares(10)
#for i in devuelPares:
# print (i)
print (next(devuelPares))# que devuelve solalamente el primer valor almacenado en el interior del objeto generador
#ENTRE LLAMADA Y LLAMADA EL OBJETO GENERADOR ENTRA EN ESTADO DE SUSPENCION, A LA SIGUIENTE LLAMADA, CONTINUA CON LA LISTA DE NUMEROS
print("Aqui podria ir mas codigo...")
print (next(devuelPares))
print("Aqui podria ir mas codigo...")
print (next(devuelPares))