Files
2025_12_15_python/dzien_05/klasy_03_tl.py
2025-12-19 10:12:04 +01:00

53 lines
1.4 KiB
Python

class Computer:
def __init__(self, info: str, typ: str, speed: int):
print("Startujemy...")
# definicja właściwości obiektów tej lasy
self.procesor = "CPU at start"
self.speed = "5 GHz"
self.cpu_speed = speed
self.informacja = info
self.typ = typ
def __str__(self):
return f"To jest {id(self)=}"
def informacje(self):
if self.cpu_speed < 3000:
text = "- to jest wolny komputer"
else:
text = "- to jest szybki komputer"
return f"Info: {self.informacja} / {text}"
# TypeError:
# Computer.__init__()
# missing 1 required positional argument:
# 'info'
komputer1 = Computer("Komputer z lat 90tych", "XT", 1200)
komputer2 = Computer("Inna informacja", "AT", 4000)
print(komputer1)
print('-------------------')
print(dir(komputer1))
print(dir(komputer2))
print('-------------------')
print(komputer1.procesor)
print(komputer2.procesor)
komputer1.procesor = "AMD M6"
print('-------------------')
print(komputer1.procesor)
print(komputer2.procesor)
print('-------------------')
komputer1.nowe_property = "Jakaś tam"
print(dir(komputer1))
print(dir(komputer2))
print('-------------------')
# print(komputer1.informacje)
# <bound method Computer.informacje
# of <__main__.Computer object
# at 0x7d072baa3860>>
print(komputer1.informacje())
print(komputer2.informacje())