You've already forked Curso-lenguaje-python
Update Python Ofensivo
This commit is contained in:
30
python-ofensivo/00_ejercicios/05_encapsulamiento10.py
Normal file
30
python-ofensivo/00_ejercicios/05_encapsulamiento10.py
Normal file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Métodos especiales
|
||||
"""
|
||||
|
||||
|
||||
class Contador:
|
||||
|
||||
def __init__(self, limite):
|
||||
|
||||
self.limite = limite
|
||||
|
||||
def __iter__(self):
|
||||
|
||||
self.valor = 0
|
||||
|
||||
return self
|
||||
|
||||
def __next__(self):
|
||||
|
||||
if self.valor < self.limite:
|
||||
self.valor += 1
|
||||
return self.valor
|
||||
else:
|
||||
raise StopIteration
|
||||
|
||||
c = Contador(5)
|
||||
|
||||
for i in c:
|
||||
print(i)
|
||||
Reference in New Issue
Block a user