Python 3.13.0 (tags/v3.13.0:60403a5, Oct 7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
DreamPie 1.2.1
>>> def f(a, b, c):
... print(a, b, c)
>>> f(1, 2, 3)
1 2 3
>>> xs = (1, 2, 3)
>>> f(xs)
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
f(xs)
~^^^^
TypeError: f() missing 2 required positional arguments: 'b' and 'c'
>>> f(*xs)
1 2 3
>>> def f(a, b, c):
... print(a, b, c)
... return None
>>> f
0: <function f at 0x00000207FF2225C0>
>>> def f():
... yield 1
... yield 2
... return None
... yield 3
>>> f
1: <function f at 0x00000207FF2223E0>
>>> f()
2: <generator object f at 0x00000207FE9DD7A0>
>>> g = f()
>>> dir(g)
3: ['__class__',
'__class_getitem__',
'__del__',
'__delattr__',
'__dir__',
'__doc__',
'__eq__',
'__format__',
'__ge__',
'__getattribute__',
'__getstate__',
'__gt__',
'__hash__',
'__init__',
'__init_subclass__',
'__iter__',
'__le__',
'__lt__',
'__name__',
'__ne__',
'__new__',
'__next__',
'__qualname__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__setattr__',
'__sizeof__',
'__str__',
'__subclasshook__',
'close',
'gi_code',
'gi_frame',
'gi_running',
'gi_suspended',
'gi_yieldfrom',
'send',
'throw']
>>> g
4: <generator object f at 0x00000207FE9DDB10>
>>> next(g)
5: 1
>>> next(g)
6: 2
>>> next(g)
Traceback (most recent call last):
File "<pyshell#15>", line 1, in <module>
next(g)
~~~~^^^
StopIteration
>>> def f():
... yield 1
... yield 2
... return None
... yield 3
>>> for i in f():
... print(i)
1
2
>>> def f():
... print('A')
... yield 1
... print('B')
... yield 2
... print('C')
... return None
... print('D')
... yield 3
>>> g = f()
>>> next(g)
A
7: 1
>>> next(g)
B
8: 2
>>> next(g)
C
Traceback (most recent call last):
File "<pyshell#22>", line 1, in <module>
next(g)
~~~~^^^
StopIteration
>>> next(g)
Traceback (most recent call last):
File "<pyshell#23>", line 1, in <module>
next(g)
~~~~^^^
StopIteration
>>> def dekorátor(funkce):
... return funkce
>>> def fn():
... print('Ahoj!')
>>> fn
9: <function fn at 0x00000207FF222980>
>>> fn()
Ahoj!
>>> @dekorátor
... def fn():
... print('Ahoj!')
>>> fn
10: <function fn at 0x00000207FF222A20>
>>> fn()
Ahoj!
>>> def dekorátor(funkce):
... print('Dekoruji...')
... return funkce
>>> @dekorátor
... def fn():
... print('Ahoj!')
Dekoruji...
>>> fn()
Ahoj!
>>> def dekorátor(funkce):
... from time import time
... print(f'Volám funkci {funkce.name}() v čase {time()}.')
... return funkce
>>> @dekorátor
... def fn():
... print('Ahoj!')
Traceback (most recent call last):
File "<pyshell#35>", line 1, in <module>
@dekorátor
^^^^^^^^^
File "<pyshell#34>", line 3, in dekorátor
print(f'Volám funkci {funkce.name}() v čase {time()}.')
^^^^^^^^^^^
AttributeError: 'function' object has no attribute 'name'
>>> dir(fn)
11: ['__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__',
'__type_params__']
[About 37 more lines. Double-click to unfold]
>>> def dekorátor(funkce):
... from time import time
... print(f'Volám funkci {funkce.__name__}() v čase {time()}.')
... return funkce
>>> dir(fn)
12: ['__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__',
'__type_params__']
[About 37 more lines. Double-click to unfold]
>>> @dekorátor
... def fn():
... print('Ahoj!')
Volám funkci fn() v čase 1731664704.8950157.
>>> def _omez_hodnoty(funkce):
... def __omez_hodnoty(xs):
... ret = funkce( [x for x in xs] )
... return ret
... return __omez_hodnoty
>>> @_omez_hodnoty
... def zpracuj_hodnoty(xs):
... return [x**2 for x in xs]
>>> zpracuj_hodnoty( [1, 3, 11, 4, 7, 14, 5] )
13: [1, 9, 121, 16, 49, 196, 25]
>>> def _omez_hodnoty(funkce):
... def __omez_hodnoty(xs):
... ret = funkce( [x for x in xs if x <= 7] )
... return ret
... return __omez_hodnoty
>>> @_omez_hodnoty
... def zpracuj_hodnoty(xs):
... return [x**2 for x in xs]
>>> zpracuj_hodnoty( [1, 3, 11, 4, 7, 14, 5] )
14: [1, 9, 16, 49, 25]
>>> def omez_hodnoty(maximum):
... def _omez_hodnoty(funkce):
... def __omez_hodnoty(xs):
... ret = funkce( [x for x in xs if x <= maximum] )
... return ret
... return __omez_hodnoty
... return _omez_hodnoty
>>> @_omez_hodnoty(7)
... def zpracuj_hodnoty(xs):
... return [x**2 for x in xs]
Traceback (most recent call last):
File "<pyshell#47>", line 1, in <module>
@_omez_hodnoty(7)
~~~~~~~~~~~~~^^^
File "<pyshell#43>", line 3, in __omez_hodnoty
ret = funkce( [x for x in xs if x <= 7] )
^^
TypeError: 'function' object is not iterable
>>> @omez_hodnoty(7)
... def zpracuj_hodnoty(xs):
... return [x**2 for x in xs]
>>> zpracuj_hodnoty( [1, 3, 11, 4, 7, 14, 5] )
15: [1, 9, 16, 49, 25]
>>> @omez_hodnoty(10)
... def zpracuj_hodnoty(xs):
... return [x**2 for x in xs]
>>> zpracuj_hodnoty( [1, 3, 11, 4, 7, 14, 5] )
16: [1, 9, 16, 49, 25]
>>> @omez_hodnoty(11)
... def zpracuj_hodnoty(xs):
... return [x**2 for x in xs]
>>> zpracuj_hodnoty( [1, 3, 11, 4, 7, 14, 5] )
17: [1, 9, 121, 16, 49, 25]
>>> zpracuj_hodnoty.__name__
18: '__omez_hodnoty'
>>> from functools import wraps
... def omez_hodnoty(maximum):
... def _omez_hodnoty(funkce):
... @wraps(funkce)
... def __omez_hodnoty(xs):
... ret = funkce( [x for x in xs if x <= maximum] )
... return ret
... return __omez_hodnoty
... return _omez_hodnoty
>>> @omez_hodnoty(11)
... def zpracuj_hodnoty(xs):
... return [x**2 for x in xs]
>>> zpracuj_hodnoty( [1, 3, 11, 4, 7, 14, 5] )
19: [1, 9, 121, 16, 49, 25]
>>> zpracuj_hodnoty.__name__
20: 'zpracuj_hodnoty'
>>> xs = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
>>> for a in xs:
... b = next(xs)
... print(a, b)
Traceback (most recent call last):
File "<pyshell#60>", line 2, in <module>
b = next(xs)
TypeError: 'tuple' object is not an iterator
>>> i = iter(xs)
... for a in i:
... b = next(i)
... print(a, b)
1 2
3 4
5 6
7 8
9 10
>>> int('10010')
21: 10010
>>> int('10010', 2)
22: 18
>>> int('10010', base=2)
23: 18
>>> def f(a, b, c=3, d='ahoj'):
... pass
>>> from inspect import getfullargspec
>>> getfullargspec(f)
24: FullArgSpec(args=['a', 'b', 'c', 'd'], varargs=None, varkw=None, defaults=(3, 'ahoj'), kwonlyargs=[], kwonlydefaults=None, annotations={})
>>> def f(a: int, b: 'Baf!', c: float=3, d: str='ahoj') -> (666, list):
... pass
>>> getfullargspec(f)
25: FullArgSpec(args=['a', 'b', 'c', 'd'], varargs=None, varkw=None, defaults=(3, 'ahoj'), kwonlyargs=[], kwonlydefaults=None, annotations={'return': (666, <class 'list'>), 'a': <class 'int'>, 'b': 'Baf!', 'c': <class 'float'>, 'd': <class 'str'>})
>>>