Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. DreamPie 1.2.1 >>> class Třída: ... ... třídní_proměnná = 666 ... ... def instanční_metoda(self, x): ... print(x) >>> Třída 0: <class '__main__.Třída'> >>> Třída.třídní_proměnná 1: 666 >>> Třída.instanční_metoda 2: <function Třída.instanční_metoda at 0x000002A49280B7E0> >>> Třída.instanční_metoda() Traceback (most recent call last): File "<pyshell#4>", line 1, in <module> Třída.instanční_metoda() TypeError: Třída.instanční_metoda() missing 2 required positional arguments: 'self' and 'x' >>> Třída.instanční_metoda('ahoj') Traceback (most recent call last): File "<pyshell#5>", line 1, in <module> Třída.instanční_metoda('ahoj') TypeError: Třída.instanční_metoda() missing 1 required positional argument: 'x' >>> Třída.instanční_metoda('ahoj', 'Baf!') Baf! >>> Třída.instanční_metoda 3: <function Třída.instanční_metoda at 0x000002A49280B7E0> >>> t = Třída() >>> t 4: <__main__.Třída object at 0x000002A492802E50> >>> t.třídní_proměnná 5: 666 >>> t.instanční_metoda 6: <bound method Třída.instanční_metoda of <__main__.Třída object at 0x000002A492802E50>> >>> t.instanční_metoda() Traceback (most recent call last): File "<pyshell#12>", line 1, in <module> t.instanční_metoda() TypeError: Třída.instanční_metoda() missing 1 required positional argument: 'x' >>> t.instanční_metoda(333) 333 >>> class Třída: ... ... třídní_proměnná = 666 ... ... def instanční_metoda(self, x): ... print('self:', self) ... print('x:', x) >>> Třída.instanční_metoda('ahoj', 'Baf!') self: ahoj x: Baf! >>> t = Třída() >>> t.instanční_metoda(333) self: <__main__.Třída object at 0x000002A49281EF50> x: 333 >>> t 7: <__main__.Třída object at 0x000002A49281EF50> >>> class Třída: ... ... třídní_proměnná = 666 ... ... def instanční_metoda(self, x): ... print('self:', self) ... print('x:', x) ... ... @classmethod ... def třídní_metoda(cls, x): ... print('cls:', cls) ... print('cls.x:', cls.x) ... print('x:', x) >>> t = Třída() >>> t.třídní_metoda() Traceback (most recent call last): File "<pyshell#21>", line 1, in <module> t.třídní_metoda() TypeError: Třída.třídní_metoda() missing 1 required positional argument: 'x' >>> t.třídní_metoda(333) cls: <class '__main__.Třída'> Traceback (most recent call last): File "<pyshell#22>", line 1, in <module> t.třídní_metoda(333) File "<pyshell#19>", line 12, in třídní_metoda print('cls.x:', cls.x) ^^^^^ AttributeError: type object 'Třída' has no attribute 'x' >>> class Třída: ... ... třídní_proměnná = 666 ... ... def instanční_metoda(self, x): ... print('self:', self) ... print('x:', x) ... ... @classmethod ... def třídní_metoda(cls, x): ... print('cls:', cls) ... print('cls.x:', cls.x) ... print('x:', x) >>> class Třída: ... ... třídní_proměnná = 666 ... ... def instanční_metoda(self, x): ... print('self:', self) ... print('x:', x) ... ... @classmethod ... def třídní_metoda(cls, x): ... print('cls:', cls) ... print('cls.třídní_proměnná:', cls.třídní_proměnná) ... print('x:', x) >>> t = Třída() >>> t.třídní_metoda(333) cls: <class '__main__.Třída'> cls.třídní_proměnná: 666 x: 333 >>> Třída 8: <class '__main__.Třída'> >>> class Třída: ... ... třídní_proměnná = 666 ... ... def instanční_metoda(self, x): ... print('self:', self) ... print('x:', x) ... ... @classmethod ... def třídní_metoda(cls, x): ... print('cls:', cls) ... print('cls.třídní_proměnná:', cls.třídní_proměnná) ... print('x:', x) ... ... @staticmethod ... def funkce(x): ... print('x:', x) >>> t = Třída() >>> Třída.funkce('Baf!') x: Baf! >>> t.funkce('Baf!') x: Baf! >>> class Třída: ... ... třídní_proměnná = 666 ... ... def instanční_metoda(self, x): ... print('self:', self) ... print('x:', x) ... ... @classmethod ... def třídní_metoda(cls, x): ... print('cls:', cls) ... print('cls.třídní_proměnná:', cls.třídní_proměnná) ... print('x:', x) ... ... @staticmethod ... def funkce(x): ... print('x:', x) ... print('třídní_proměnná:', třídní_proměnná) >>> t = Třída() >>> t.funkce('Baf!') x: Baf! Traceback (most recent call last): File "<pyshell#34>", line 1, in <module> t.funkce('Baf!') File "<pyshell#32>", line 18, in funkce print('třídní_proměnná:', třídní_proměnná) ^^^^^^^^^^^^^^^ NameError: name 'třídní_proměnná' is not defined >>> class Třída: ... ... def __fn(self): ... print('Haf!') >>> Třída.__fn Traceback (most recent call last): File "<pyshell#36>", line 1, in <module> Třída.__fn AttributeError: type object 'Třída' has no attribute '__fn' >>> t = Třída() >>> t.__fn Traceback (most recent call last): File "<pyshell#38>", line 1, in <module> t.__fn AttributeError: 'Třída' object has no attribute '__fn' >>> t.Třída__fn Traceback (most recent call last): File "<pyshell#39>", line 1, in <module> t.Třída__fn AttributeError: 'Třída' object has no attribute 'Třída__fn' >>> t._Třída__fn 9: <bound method Třída.__fn of <__main__.Třída object at 0x000002A49281FCD0>> >>> t._Třída__fn() Haf! >>> Třída._Třída__fn() Traceback (most recent call last): File "<pyshell#42>", line 1, in <module> Třída._Třída__fn() TypeError: Třída.__fn() missing 1 required positional argument: 'self' >>> class T: ... ... def __getitem__(self, x): ... print(x) >>> t = T() >>> t[0] 0 >>> t[0:2] slice(0, 2, None) >>> t[0:2:] slice(0, 2, None) >>> t['ahoj'] ahoj >>> t[(2, 'ahoj')] (2, 'ahoj') >>> t[0::2] slice(0, None, 2) >>> t[::] slice(None, None, None) >>> class Student: ... ... def __init__(self, jméno, známka, věk): ... self.jméno = jméno ... self.známka = známka ... self.věk = věk ... ... def __repr__(self): ... return repr((self.jméno, self.známka, self.věk)) >>> studenti = [ ... Student('John', 'A', 15), ... Student('Jane', 'B', 12), ... Student('Dave', 'B', 10), ... ] >>> studenti 10: [('John', 'A', 15), ('Jane', 'B', 12), ('Dave', 'B', 10)] >>> class Student: ... ... def __init__(self, jméno, známka, věk): ... self.jméno = jméno ... self.známka = známka ... self.věk = věk >>> studenti = [ ... Student('John', 'A', 15), ... Student('Jane', 'B', 12), ... Student('Dave', 'B', 10), ... ] >>> studenti 11: [<__main__.Student object at 0x000002A49283E4D0>, <__main__.Student object at 0x000002A49283E690>, <__main__.Student object at 0x000002A49283E610>] >>> class Student: ... ... def __init__(self, jméno, známka, věk): ... self.jméno = jméno ... self.známka = známka ... self.věk = věk ... ... def __repr__(self): ... return repr((self.jméno, self.známka, self.věk)) >>> studenti 12: [<__main__.Student object at 0x000002A49283E4D0>, <__main__.Student object at 0x000002A49283E690>, <__main__.Student object at 0x000002A49283E610>] >>> studenti = [ ... Student('John', 'A', 15), ... Student('Jane', 'B', 12), ... Student('Dave', 'B', 10), ... ] >>> studenti 13: [('John', 'A', 15), ('Jane', 'B', 12), ('Dave', 'B', 10)] >>> sorted(studenti) Traceback (most recent call last): File "<pyshell#62>", line 1, in <module> sorted(studenti) TypeError: '<' not supported between instances of 'Student' and 'Student' >>> class Student: ... ... def __init__(self, jméno, známka, věk): ... self.jméno = jméno ... self.známka = známka ... self.věk = věk ... ... def __repr__(self): ... return repr((self.jméno, self.známka, self.věk)) ... ... def __lt__(self, jiný_student): ... return self.věk < jiný_student.věk >>> studenti = [ ... Student('John', 'A', 15), ... Student('Jane', 'B', 12), ... Student('Dave', 'B', 10), ... ] >>> studenti 14: [('John', 'A', 15), ('Jane', 'B', 12), ('Dave', 'B', 10)] >>> sorted(studenti) 15: [('Dave', 'B', 10), ('Jane', 'B', 12), ('John', 'A', 15)] >>> Student('John', 'A', 15) < Student('Jane', 'B', 12) 16: False >>> class Student: ... ... def __init__(self, jméno, známka, věk): ... assert type(věk) == int ... self.jméno = jméno ... self.známka = známka ... self.věk = věk ... ... def __repr__(self): ... return repr((self.jméno, self.známka, self.věk)) ... ... def __lt__(self, jiný_student): ... return self.věk < jiný_student.věk >>> studenti = [ ... Student('John', 'A', 15), ... Student('Jane', 'B', 12), ... Student('Dave', 'B', 10), ... ] >>> Student('John', 'A', 'XV') Traceback (most recent call last): File "<pyshell#70>", line 1, in <module> Student('John', 'A', 'XV') File "<pyshell#68>", line 4, in __init__ assert type(věk) == int AssertionError >>> int('123') 17: 123 >>> int('1a23') Traceback (most recent call last): File "<pyshell#72>", line 1, in <module> int('1a23') ValueError: invalid literal for int() with base 10: '1a23' >>> dir('') 18: ['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isascii', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'removeprefix', 'removesuffix', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill'] [About 80 more lines. Double-click to unfold] >>> class Plocha: ... ... def __init__(self, barva=None): ... self._barva = barva ... ... def get_barvu(self): ... print("Vracím barvu.") ... return self._barva ... ... def set_barvu(self, val): ... print("Nastavuji barvu na:", val) ... self._barva = val ... ... barva = property(get_barvu, set_barvu) >>> dir(Plocha) 19: ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'barva', 'get_barvu', 'set_barvu'] [About 29 more lines. Double-click to unfold] >>> p = Plocha() >>> p 20: <__main__.Plocha object at 0x000002A49284A3D0> >>> dir(p) 21: ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_barva', 'barva', 'get_barvu', 'set_barvu'] [About 30 more lines. Double-click to unfold] >>> class Plocha: ... ... def __init__(self, barva=None): ... self._barva = barva ... ... @property ... def barva(self): ... print("Vracím barvu.") ... return self._barva ... ... @barva.setter ... def barva(self, val): ... print("Nastavuji barvu na:", val) ... self._barva = val >>> dir(Plocha) 22: ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'barva'] >>> Plocha.__dict__ 23: mappingproxy({'__dict__': <attribute '__dict__' of 'Plocha' objects>, '__doc__': None, '__init__': <function Plocha.__init__ at 0x000002A492834680>, '__module__': '__main__', '__weakref__': <attribute '__weakref__' of 'Plocha' objects>, 'barva': <property object at 0x000002A492856D40>}) >>> class Plocha: ... ... def __init__(self, barva=None): ... self._barva = barva ... ... def get_barvu(self): ... print("Vracím barvu.") ... return self._barva ... ... def set_barvu(self, val): ... print("Nastavuji barvu na:", val) ... self._barva = val ... ... barva = property(get_barvu, set_barvu) >>> Plocha.__dict__ 24: mappingproxy({'__dict__': <attribute '__dict__' of 'Plocha' objects>, '__doc__': None, '__init__': <function Plocha.__init__ at 0x000002A492834900>, '__module__': '__main__', '__weakref__': <attribute '__weakref__' of 'Plocha' objects>, 'barva': <property object at 0x000002A492855080>, 'get_barvu': <function Plocha.get_barvu at 0x000002A492834720>, 'set_barvu': <function Plocha.set_barvu at 0x000002A4928347C0>}) >>> class T: ... ... x = 666 ... ... @staticmethod ... def fn(): ... pass ... ... def fun(self): ... pass >>> T.__dict__ 25: mappingproxy({'__dict__': <attribute '__dict__' of 'T' objects>, '__doc__': None, '__module__': '__main__', '__weakref__': <attribute '__weakref__' of 'T' objects>, 'fn': <staticmethod(<function T.fn at 0x000002A492834B80>)>, 'fun': <function T.fun at 0x000002A492834C20>, 'x': 666}) >>> Plocha.__dict__ 26: mappingproxy({'__dict__': <attribute '__dict__' of 'Plocha' objects>, '__doc__': None, '__init__': <function Plocha.__init__ at 0x000002A492834900>, '__module__': '__main__', '__weakref__': <attribute '__weakref__' of 'Plocha' objects>, 'barva': <property object at 0x000002A492855080>, 'get_barvu': <function Plocha.get_barvu at 0x000002A492834720>, 'set_barvu': <function Plocha.set_barvu at 0x000002A4928347C0>}) >>> Plocha.barva 27: <property object at 0x000002A492855080> >>> dir(Plocha.barva) 28: ['__class__', '__delattr__', '__delete__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__get__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__isabstractmethod__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__set__', '__set_name__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'deleter', 'fdel', 'fget', 'fset', 'getter', 'setter'] [About 34 more lines. Double-click to unfold] >>>