Python 3.13.3 (tags/v3.13.3:6280bb5, Apr 8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. DreamPie 1.2.1 >>> 3**2 0: 9 >>> abs(-9) 1: 9 >>> abs(-9.7) 2: 9.7 >>> import math >>> dir(math) 3: ['__doc__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'cbrt', 'ceil', 'comb', 'copysign', 'cos', 'cosh', 'degrees', 'dist', 'e', 'erf', 'erfc', 'exp', 'exp2', 'expm1', 'fabs', 'factorial', 'floor', 'fma', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'isqrt', 'lcm', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'nextafter', 'perm', 'pi', 'pow', 'prod', 'radians', 'remainder', 'sin', 'sinh', 'sqrt', 'sumprod', 'tan', 'tanh', 'tau', 'trunc', 'ulp'] [About 66 more lines. Double-click to unfold] >>> math.pi 4: 3.141592653589793 >>> 4.2 / 2 5: 2.1 >>> 4.2 % 2 6: 0.20000000000000018 >>> 4.2 // 2 7: 2.0 >>> dir('') 8: ['__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] >>> 'abc'[-1] 9: 'c' >>> for x in xs: ... print(x) Traceback (most recent call last): File "<pyshell#11>", line 1, in <module> for x in xs: ^^ NameError: name 'xs' is not defined >>> for x in 'abc': ... print(x) a b c >>> for x in ('a', 'b', 'c'): ... print(x) a b c >>> for x in ['a', 'b', 'c']: ... print(x) a b c >>> for x in {'a', 'b', 'c'}: ... print(x) b c a >>> for x in enumerate('abc'): ... print(x) (0, 'a') (1, 'b') (2, 'c') >>> for x in enumerate('abc', start=11): ... print(x) (11, 'a') (12, 'b') (13, 'c') >>> x 10: (13, 'c') >>> xs = 'abc' >>> xs 11: 'abc' >>> xs.capitalize() 12: 'Abc' >>> xs.upper() 13: 'ABC' >>> x, y, z = xs >>> x 14: 'a' >>> y 15: 'b' >>> z 16: 'c' >>> y, z = z, y >>> y 17: 'c' >>> z 18: 'b' >>> xs 19: 'abc' >>> x, *_ = xs >>> x 20: 'a' >>> _ 21: 'a' >>> x, *_, y = 'abcdef' >>> x 22: 'a' >>> y 23: 'f' >>> x, *z, y = 'abcdef' >>> x 24: 'a' >>> y 25: 'f' >>> z 26: ['b', 'c', 'd', 'e'] >>> x, z, y = 'af' Traceback (most recent call last): File "<pyshell#41>", line 1, in <module> x, z, y = 'af' ^^^^^^^ ValueError: not enough values to unpack (expected 3, got 2) >>> x, *z, y = 'af' >>> x 27: 'a' >>> y 28: 'f' >>> z 29: [] >>> x, *z, y = 'abcdef' >>> z 30: ['b', 'c', 'd', 'e'] >>> len(z) 31: 4 >>> dir(z) 32: ['__add__', '__class__', '__class_getitem__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getstate__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] [About 47 more lines. Double-click to unfold] >>> xs = 'Harry Potter and the Order of the Phoenix' >>> xs 33: 'Harry Potter and the Order of the Phoenix' >>> len('Harry Potter and the ') 34: 21 >>> xs[22:] 35: 'rder of the Phoenix' >>> xs[21:] 36: 'Order of the Phoenix' >>> xs[1] 37: 'a' >>> xs[0] 38: 'H' >>> xs = 'abcdefgh' ... for x in xs: ... print(x) a b c d e f g h >>> i = iter(xs) >>> for x in i: ... print(x) a b c d e f g h >>> i = iter(xs) >>> next(i) 39: 'a' >>> next(i) 40: 'b' >>> next(i) 41: 'c' >>> next(i) 42: 'd' >>> next(i) 43: 'e' >>> next(i) 44: 'f' >>> next(i) 45: 'g' >>> next(i) 46: 'h' >>> next(i) Traceback (most recent call last): File "<pyshell#69>", line 1, in <module> next(i) ~~~~^^^ StopIteration >>> i = iter(xs) >>> next(i) 47: 'a' >>> next(i) 48: 'b' >>> next(i) 49: 'c' >>> next(i) 50: 'd' >>> for x in i: ... print(x) e f g h >>> xs 51: 'abcdefgh' >>> dir(xs) 52: ['__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] >>> i = iter(xs) >>> dir(i) 53: ['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__length_hint__', '__lt__', '__ne__', '__new__', '__next__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__'] [About 27 more lines. Double-click to unfold] >>> bin(0) 54: '0b0' >>> bin(1) 55: '0b1' >>> bin(2) 56: '0b10' >>> bin(3) 57: '0b11' >>> bin(4) 58: '0b100' >>> int('1000000', 2) 59: 64 >>> int('1111111', 2) 60: 127 >>> int('11111111', 2) 61: 255 >>> xs = "$1,006,968,171" >>> xs 62: '$1,006,968,171' >>> xs[1:] 63: '1,006,968,171' >>> xs[1:].replace(',', '') 64: '1006968171' >>> int('1006968171') 65: 1006968171 >>> int(xs[1:].replace(',', '')) 66: 1006968171 >>> names = ["John", "Wendy", "Pete", "Jane", "David", "Amanda", "Ix"] >>> names 67: ['John', 'Wendy', 'Pete', 'Jane', 'David', 'Amanda', 'Ix'] >>> for name in names: ... print(name) John Wendy Pete Jane David Amanda Ix >>> for name in sorted(names): ... print(name) Amanda David Ix Jane John Pete Wendy >>> for name in sorted(names, key=lambda name: len(name)): ... print(name) Ix John Pete Jane Wendy David Amanda >>> names 68: ['John', 'Wendy', 'Pete', 'Jane', 'David', 'Amanda', 'Ix'] >>> def fn(name): ... return len(name) ... ... for name in sorted(names, key=fn): ... print(name) Ix John Pete Jane Wendy David Amanda >>> def fn(name): ... return len(name), name ... ... for name in sorted(names, key=fn): ... print(name) Ix Jane John Pete David Wendy Amanda >>> def fn(name): ... return (len(name), name) ... ... for name in sorted(names, key=fn): ... print(name) Ix Jane John Pete David Wendy Amanda >>> def fn(name): ... return ( ... len(name), name ... ) ... ... for name in sorted(names, key=fn): ... print(name) Ix Jane John Pete David Wendy Amanda >>> #for name in sorted(names, key=lambda name: len(name), name): ... # print(name) >>> for name in sorted(names, key=lambda name: (len(name), name)): ... print(name) Ix Jane John Pete David Wendy Amanda >>>