r
This commit is contained in:
@@ -1,17 +1,29 @@
|
|||||||
class Computer:
|
class Computer:
|
||||||
def __init__(self):
|
def __init__(self, info: str, typ: str):
|
||||||
print("Startujemy...")
|
print("Startujemy...")
|
||||||
# definicja właściwości obiektów tej lasy
|
# definicja właściwości obiektów tej lasy
|
||||||
self.procesor = "CPU at start"
|
self.procesor = "CPU at start"
|
||||||
self.speed = "5 GHz"
|
self.speed = "5 GHz"
|
||||||
self.cpu_speed = 5000
|
self.cpu_speed = 5000
|
||||||
|
self.informacja = info
|
||||||
|
self.typ = typ
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"To jest {id(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:
|
||||||
komputer1 = Computer()
|
# Computer.__init__()
|
||||||
komputer2 = Computer()
|
# missing 1 required positional argument:
|
||||||
|
# 'info'
|
||||||
|
komputer1 = Computer("Komputer z lat 90tych", "XT", 1200)
|
||||||
|
komputer2 = Computer("Inna informacja", "AT")
|
||||||
|
|
||||||
print(komputer1)
|
print(komputer1)
|
||||||
print('-------------------')
|
print('-------------------')
|
||||||
@@ -30,4 +42,11 @@ print('-------------------')
|
|||||||
komputer1.nowe_property = "Jakaś tam"
|
komputer1.nowe_property = "Jakaś tam"
|
||||||
print(dir(komputer1))
|
print(dir(komputer1))
|
||||||
print(dir(komputer2))
|
print(dir(komputer2))
|
||||||
print('-------------------')
|
print('-------------------')
|
||||||
|
|
||||||
|
# print(komputer1.informacje)
|
||||||
|
# <bound method Computer.informacje
|
||||||
|
# of <__main__.Computer object
|
||||||
|
# at 0x7d072baa3860>>
|
||||||
|
|
||||||
|
print(komputer1.informacje())
|
||||||
Reference in New Issue
Block a user