<jupyter_start><jupyter_text>Python (EPAM, 2020), lecture 01  What the `python` is?> Python is a simple, yet powerful, interpreted programming language that bridges the gap between C and shell programming, and is thus ideally suited for "throw-away programming" and rapid prototyping(c) [python 1.4 ref](https://docs.python.org/release/1.4/ref/ref0.htmlHDT0)> Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python’s elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms.(c) [python 3.9 ref](https://docs.python.org/release/3.9.0/tutorial/index.htmltutorial-index) **Keywords**:1. easy to learn?1. high-level data structures? stdlib with batteries inside. By the way sometimes they [remove dead batteries](https://www.python.org/dev/peps/pep-0594/)1. elegant syntax? For us it means: [PEP-8](https://www.python.org/dev/peps/pep-0008/), `black` + `isort` formatting1. dynamic types? duck typing!<jupyter_code>foo = 5
bar = foo + 5
baz = bar + "bar"<jupyter_output><empty_output><jupyter_text>Python types![python_types.png](img/python_types.png)_Note_:Some data types such as [`Ellipsis`](https://stackoverflow.com/questions/772124/what-does-the-ellipsis-object-do) are not presented here ^  Lets check some variables type<jupyter_code>a = 6
b = object()
c = [1, 2, 3, 4, 5, 6]
d = ...


def e():
    ...


class F(list):
    pass


for var in (a, b, c, d, e, F):
    print(f"{var=}, its type is {type(var)=}")

print(f"type of 6.0 {type(6.0)}")<jupyter_output><empty_output><jupyter_text>_Note_: even if I showed it, do not use `type()` for type-checking :-)Usually type check is performed using `isinstance(...)` function  Python statementsHow can we operate with data?  Conditions<jupyter_code>a, b = 5, 6


if a < b:
    print(f"{a=} is the less than other variable")
elif b < a:
    print(f"{b=} is the less than other variable")
else:
    print(f"Seems like a == b == {a}")<jupyter_output><empty_output><jupyter_text>Iterations and loops<jupyter_code>for val in [1, 2, 3, 4, 5, 6]:
    print(f"{val=}", end=" ")
else:
    print("That's all, folks!")

i = 63215

while i & (i - 1):
    i += 1

print(f"{i=}")<jupyter_output><empty_output><jupyter_text>Falsy valuesThe above examples shows Falsy values usage ([doc reference](https://docs.python.org/3/library/stdtypes.htmltruth-value-testing)).<jupyter_code>from decimal import Decimal
from fractions import Fraction


just_falsy_values = [False, None]
numeric_falsy_values = [0, 0.0, 0j, Decimal(0), Fraction(0, 1)]
empty_sequencies_and_collections = [[], (), "", range(0), {}, set()]


assert not any(just_falsy_values)
assert not any(numeric_falsy_values)
assert not any(empty_sequencies_and_collections)<jupyter_output><empty_output><jupyter_text>How could we use it?<jupyter_code># this code probably contain bugs...


def _check_window(x: int, y: int, z: int) -> bool:
    return (x + y) == z


data_to_process = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765]


assert len(data_to_process) >= 3

a, b, c = data_to_process[0], data_to_process[1], data_to_process[2]

while data_to_process:
    if not _check_window(a, b, c):
        raise ValueError("Invalid data")

    a, b, c = b, c, data_to_process[0]
    data_to_process = data_to_process[1:]

print("it's a fib sequence!")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13852205675751617, 'fraction_numerical': 0.03568418094970497, 'mean_word_length': 4.884297520661157, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 29, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '97324', 'license': 'MIT', 'n_tokens_mistral': 1355, 'n_tokens_neox': 1238, 'n_words': 378, 'path': 'lecture_01/materials/slideshow.ipynb', 'repo_name': 'revire/epam_python_autumn_2020', 'size': '3559'}