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
>>> xs = [1, 1.1, 1+1j, 'ahoj', (1, 'a'), {1, 'a'}, [1, 'a'], {1: 1, 'a': 666}, b'ahoj']
>>> len(xs)
0: 9
>>> for x in xs:
... print(x, type(x))
1 <class 'int'>
1.1 <class 'float'>
(1+1j) <class 'complex'>
ahoj <class 'str'>
(1, 'a') <class 'tuple'>
{1, 'a'} <class 'set'>
[1, 'a'] <class 'list'>
{1: 1, 'a': 666} <class 'dict'>
b'ahoj' <class 'bytes'>
>>> xn = 1, 'a'
>>> xn
1: (1, 'a')
>>> xs[0]
2: 1
>>> xn[0]
3: 1
>>> from collections import namedtuple
>>> Bod = namedtuple('bod', 'x y')
>>> b = Bod(1, 2)
>>> b
4: bod(x=1, y=2)
>>> b.x
5: 1
>>> b.y
6: 2
>>> b[0]
7: 1
>>> b[1]
8: 2
>>> b[-1]
9: 2
>>> x
10: b'ahoj'
>>> y
Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
y
NameError: name 'y' is not defined
>>> from dataclasses import make_dataclass
>>> Bod2D = dataclass('bod_2d', ['x', 'y'])
Traceback (most recent call last):
File "<pyshell#19>", line 1, in <module>
Bod2D = dataclass('bod_2d', ['x', 'y'])
^^^^^^^^^
NameError: name 'dataclass' is not defined
>>> Bod2D = make_dataclass('bod_2d', ['x', 'y'])
>>> b2 = Bod2D(2, 1)
>>> b2
11: bod_2d(x=2, y=1)
>>> b
12: bod(x=1, y=2)
>>> b[0]
13: 1
>>> b.x
14: 1
>>> b2[0]
Traceback (most recent call last):
File "<pyshell#26>", line 1, in <module>
b2[0]
~~^^^
TypeError: 'bod_2d' object is not subscriptable
>>> b2.x
15: 2
>>> b.x = 'a'
Traceback (most recent call last):
File "<pyshell#28>", line 1, in <module>
b.x = 'a'
^^^
AttributeError: can't set attribute
>>> b
16: bod(x=1, y=2)
>>> b2.x = 'a'
>>> b2
17: bod_2d(x='a', y=1)
>>> class Bod3D:
...
... def __init__(self, x, y, z):
... self.x = x
... self.y = y
... self.z = z
>>> b3 = Bod3D(1, 2, 3)
>>> b3
18: <__main__.Bod3D object at 0x000002A1046F4B90>
>>> b3.x
19: 1
>>> b3.x = 'a'
>>> b3.x
20: 'a'
>>> class Bod3D:
...
... def __init__(self, x, y, z):
... self.x = x
... self.y = y
... self.z = z
...
... def __str__(self):
... return f'bod_3d({self.x}, {self.y}, {self.z})'
>>> b3 = Bod3D(1, 2, 3)
>>> b3
21: <__main__.Bod3D object at 0x000002A1046F8F50>
>>> print(b3)
bod_3d(1, 2, 3)
>>> class Bod3D:
...
... def __init__(self, x, y, z):
... self.x = x
... self.y = y
... self.z = z
>>> b3 = Bod3D(1, 2, 3)
>>> print(b3)
<__main__.Bod3D object at 0x000002A1046D2050>
>>> 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
22: [('John', 'A', 15), ('Jane', 'B', 12), ('Dave', 'B', 10)]
>>> type(studenti)
23: <class 'list'>
>>> type(studenti[0])
24: <class '__main__.Student'>
>>> sorted(studenti)
Traceback (most recent call last):
File "<pyshell#50>", 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, druhý_student):
... return self.věk < druhý_student.věk
>>> studenti = [
... Student('John', 'A', 15),
... Student('Jane', 'B', 12),
... Student('Dave', 'B', 10),
... ]
>>> studenti
25: [('John', 'A', 15), ('Jane', 'B', 12), ('Dave', 'B', 10)]
>>> sorted(studenti)
26: [('Dave', 'B', 10), ('Jane', 'B', 12), ('John', 'A', 15)]
>>> class Fn:
...
... def __call__(self):
... print('Zavoláno na', self)
>>> fn = Fn()
>>> fn
27: <__main__.Fn object at 0x000002A106669010>
>>> fn()
Zavoláno na <__main__.Fn object at 0x000002A106669010>
>>> dir(1)
28: ['__abs__',
'__add__',
'__and__',
'__bool__',
'__ceil__',
'__class__',
'__delattr__',
'__dir__',
'__divmod__',
'__doc__',
'__eq__',
'__float__',
'__floor__',
'__floordiv__',
'__format__',
'__ge__',
'__getattribute__',
'__getnewargs__',
'__getstate__',
'__gt__',
'__hash__',
'__index__',
'__init__',
'__init_subclass__',
'__int__',
'__invert__',
'__le__',
'__lshift__',
'__lt__',
'__mod__',
'__mul__',
'__ne__',
'__neg__',
'__new__',
'__or__',
'__pos__',
'__pow__',
'__radd__',
'__rand__',
'__rdivmod__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__rfloordiv__',
'__rlshift__',
'__rmod__',
'__rmul__',
'__ror__',
'__round__',
'__rpow__',
'__rrshift__',
'__rshift__',
'__rsub__',
'__rtruediv__',
'__rxor__',
'__setattr__',
'__sizeof__',
'__str__',
'__sub__',
'__subclasshook__',
'__truediv__',
'__trunc__',
'__xor__',
'as_integer_ratio',
'bit_count',
'bit_length',
'conjugate',
'denominator',
'from_bytes',
'imag',
'numerator',
'real',
'to_bytes']
[About 72 more lines. Double-click to unfold]
>>> int(1).bit_count
29: <built-in method bit_count of int object at 0x00007FFBEFF9D328>
>>> int(1).bit_count()
30: 1
>>> int(10).bit_count()
31: 2
>>> int(255).bit_count()
32: 8
>>> int(255)
33: 255
>>>