Verzeichnis für teil28

This commit is contained in:
Olli Graf
2024-10-25 14:03:27 +02:00
parent af36c44e66
commit fec0969d7f
12 changed files with 2 additions and 0 deletions

25
teil28/classdecor.py Normal file
View File

@@ -0,0 +1,25 @@
# Datei: classdecor.py
def addrepr(cls):
# Universelle __repr__ Methode
def __repr__(self):
return f"{cls.__name__}({self.__dict__})"
cls.__repr__ = __repr__
return cls
@addrepr
class Fahrzeug():
def __init__(self,farbe,typ):
self.typ = typ
self.farbe = farbe
f1 = Fahrzeug('grau','VW')
f2 = Fahrzeug('rot','Ferrari')
print(f'{f1}')
print(f'{f2}')