You've already forked Curso-lenguaje-python
Update Python Ofensivo
This commit is contained in:
28
python-ofensivo/00_ejercicios/05_encapsulamiento05.py
Normal file
28
python-ofensivo/00_ejercicios/05_encapsulamiento05.py
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Métodos especiales
|
||||
"""
|
||||
|
||||
|
||||
class Caja:
|
||||
|
||||
def __init__(self, *items):
|
||||
self.items = items
|
||||
|
||||
def mostrar_items(self):
|
||||
|
||||
print("Se ha creado una caja con las siguientes frutas: ")
|
||||
|
||||
for item in self.items:
|
||||
print(item)
|
||||
|
||||
def __len__(self):
|
||||
|
||||
return len(self.items)
|
||||
|
||||
|
||||
caja = Caja("Manzana", "Pera", "Naranja", "Platano", "Melon")
|
||||
|
||||
caja.mostrar_items()
|
||||
|
||||
print("La caja tiene {} frutas".format(len(caja)))
|
||||
Reference in New Issue
Block a user