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 = range(10)
>>> xs
0: range(0, 10)
>>> list(xs)
1: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> [x for x in xs]
2: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> [3*x for x in xs if 3*x % 7 == 0]
3: [0, 21]
>>> [3*x for x in xs if 3*x % 6 == 0]
4: [0, 6, 12, 18, 24]
>>> [y for x in xs if (y := 3*x) % 6 == 0]
5: [0, 6, 12, 18, 24]
>>> xs
6: range(0, 10)
>>> ys = []
... for x in xs:
... y = 3 * x
... if y % 6 == 0:
... ys.append(y)
>>> ys
7: [0, 6, 12, 18, 24]
>>> [i for i in (1, 2, 3)]
8: [1, 2, 3]
>>> [(i, j) for i in (1, 2, 3) for j in ('a', 'b')]
9: [(1, 'a'), (1, 'b'), (2, 'a'), (2, 'b'), (3, 'a'), (3, 'b')]
>>> [(i, j, k) for i in (1, 2, 3) for j in ('a', 'b') for k in ('A', 'B')]
10: [(1, 'a', 'A'),
(1, 'a', 'B'),
(1, 'b', 'A'),
(1, 'b', 'B'),
(2, 'a', 'A'),
(2, 'a', 'B'),
(2, 'b', 'A'),
(2, 'b', 'B'),
(3, 'a', 'A'),
(3, 'a', 'B'),
(3, 'b', 'A'),
(3, 'b', 'B')]
>>> [(i, j) for i in range(2) for j in range(2)]
11: [(0, 0), (0, 1), (1, 0), (1, 1)]
>>> [(i, j, i & j, i | j) for i in range(2) for j in range(2)]
12: [(0, 0, 0, 0), (0, 1, 0, 1), (1, 0, 0, 1), (1, 1, 1, 1)]
>>> from collection import namedtuple
Traceback (most recent call last):
File "<pyshell#15>", line 1, in <module>
from collection import namedtuple
ModuleNotFoundError: No module named 'collection'
>>> from collections import namedtuple
>>> Record = namedtuple('Záznam', 'x y and or')
Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
Record = namedtuple('Záznam', 'x y and or')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\znamenaj\Python311\Lib\collections\__init__.py", line 396, in namedtuple
raise ValueError('Type names and field names cannot be a '
ValueError: Type names and field names cannot be a keyword: 'and'
>>> Record = namedtuple('Záznam', 'x y azároveň nebo')
>>> [Record(i, j, i & j, i | j) for i in range(2) for j in range(2)]
13: [Záznam(x=0, y=0, azároveň=0, nebo=0),
Záznam(x=0, y=1, azároveň=0, nebo=1),
Záznam(x=1, y=0, azároveň=0, nebo=1),
Záznam(x=1, y=1, azároveň=1, nebo=1)]
>>> tabulka = [Record(i, j, i & j, i | j) for i in range(2) for j in range(2)]
>>> tabulka[0]
14: Záznam(x=0, y=0, azároveň=0, nebo=0)
>>> tabulka[0].x
15: 0
>>> tabulka[0].y
16: 0
>>> tabulka[0].azároveň
17: 0
>>> tabulka[0].nebo
18: 0
>>> Record = namedtuple('Záznam', 'x y a_zároveň nebo')
>>> tabulka = [Record(i, j, i & j, i | j) for i in range(2) for j in range(2)]
>>> tabulka
19: [Záznam(x=0, y=0, a_zároveň=0, nebo=0),
Záznam(x=0, y=1, a_zároveň=0, nebo=1),
Záznam(x=1, y=0, a_zároveň=0, nebo=1),
Záznam(x=1, y=1, a_zároveň=1, nebo=1)]
>>> mocneni = [ lambda x, na=i: x ** na for i in range(4) ]
>>> mocneni[3]
20: <function <listcomp>.<lambda> at 0x000001A05003CD60>
>>> mocneni[3](2)
21: 8
>>> def fn():
... ...
>>> fn.xxx = lambda x: x**3
>>> fn
22: <function fn at 0x000001A05002BB00>
>>> fn()
>>> fn.xxx
23: <function <lambda> at 0x000001A05003CFE0>
>>> fn.xxx(2)
24: 8
>>> def moje_funkce():
... print('moje funkce')
>>> moje_funkce()
moje funkce
>>> def dekorátor(funkce):
... def _dekorátor():
... print('START')
... return funkce()
... return _dekorátor
>>> @dekorátor
... def moje_funkce():
... print('moje funkce')
>>> moje_funkce()
START
moje funkce
>>> def dekorátor(funkce):
... def _dekorátor():
... print('START')
... ret = funkce()
... print('END')
... return ret
... return _dekorátor
>>> @dekorátor
... def moje_funkce():
... print('moje funkce')
>>> moje_funkce()
START
moje funkce
END
>>> dir(moje_funkce)
25: ['__annotations__',
'__builtins__',
'__call__',
'__class__',
'__closure__',
'__code__',
'__defaults__',
'__delattr__',
'__dict__',
'__dir__',
'__doc__',
'__eq__',
'__format__',
'__ge__',
'__get__',
'__getattribute__',
'__getstate__',
'__globals__',
'__gt__',
'__hash__',
'__init__',
'__init_subclass__',
'__kwdefaults__',
'__le__',
'__lt__',
'__module__',
'__name__',
'__ne__',
'__new__',
'__qualname__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__setattr__',
'__sizeof__',
'__str__',
'__subclasshook__']
[About 36 more lines. Double-click to unfold]
>>> moje_funkce.__name__
26: '_dekorátor'
>>> def moje_funkce():
... print('moje funkce')
>>> moje_funkce.__name__
27: 'moje_funkce'
>>> '''def fn(a=3, return=5):'''
28: 'def fn(a=3, return=5):'
>>> from inspect import getfullargspec as gfas
>>> gfas(moje_funkce)
29: FullArgSpec(args=[], varargs=None, varkw=None, defaults=None, kwonlyargs=[], kwonlydefaults=None, annotations={})
>>> def fn(x, y, z=666):
... return x + y - z
>>> gfas(fn)
30: FullArgSpec(args=['x', 'y', 'z'], varargs=None, varkw=None, defaults=(666,), kwonlyargs=[], kwonlydefaults=None, annotations={})
>>> def fn(x, y, *, z=666):
... return x + y - z
>>> gfas(fn)
31: FullArgSpec(args=['x', 'y'], varargs=None, varkw=None, defaults=None, kwonlyargs=['z'], kwonlydefaults={'z': 666}, annotations={})
>>> def fn(x: int, y: 'blabla', *, z=666) -> 'BAF!':
... return x + y - z
>>> gfas(fn)
32: FullArgSpec(args=['x', 'y'], varargs=None, varkw=None, defaults=None, kwonlyargs=['z'], kwonlydefaults={'z': 666}, annotations={'return': 'BAF!', 'x': <class 'int'>, 'y': 'blabla'})
>>> def fn(x: int, y: 'blabla', *, z=666):
... return x + y - z
>>> gfas(fn)
33: FullArgSpec(args=['x', 'y'], varargs=None, varkw=None, defaults=None, kwonlyargs=['z'], kwonlydefaults={'z': 666}, annotations={'x': <class 'int'>, 'y': 'blabla'})
>>> int('34')
34: 34
>>> '34' + 2
Traceback (most recent call last):
File "<pyshell#62>", line 1, in <module>
'34' + 2
~~~~~^~~
TypeError: can only concatenate str (not "int") to str
>>> int('34') + 2
35: 36
>>> from math import pi
>>> pi
36: 3.141592653589793
>>> pi / 4
37: 0.7853981633974483
>>> from random import random
>>> random()
38: 0.7485127276523604
>>> random()
39: 0.8134590944988629
>>>