# Типи даних і їх перетворення Найкращий та найповніший документ по типам даних в Пайтоні знаходиться на офіційному сайті: https://docs.python.org/3/reference/datamodel.html#the-standard-type-hierarchy ## Числові типи (незмінні) int float bool ### Перетворення типів: ```python= print(int(12.0)) # 12 print(int(12.5)) # 12 print(int(12.9)) # 12 print(round(12.4)) # 12 print(round(12.5)) # 12 print(round(12.50000001)) # 13 print(round(11.5)) # 12 import math print(math.ceil(-11.5)) # -11 print(math.floor(-11.5)) # -12 ``` ## Незмінні типи (послідовності) str tuple bytes ```python= int("10") str(10) float("10.5") str(10.5) bool("") bool("True") bool("False") ``` ### Таблиця перетворень | | int | float | bool | str | bytes | tuple | | -------- | -------- | -------- | -------- | -------- | -------- |-------- | | **int** | `12` | `float(12)` | `bool(0)`<br />`bool(5)`|`str(12)`| ? | ? | | **float**| `int(12.5)`<br/>`round(12.5)`<br />`math.ceil(12.5)`|`12.5`<br/>`1.2e+01`|`bool(0.0)`<br />`bool(5.5e-04)`|`str(12.5)`| ? | ? | **bool** | `int(True)`<br/>`int(False)` | `float(True)`<br/>`float(False)` | `True`<br/>`False` | `str(True)` | `bytes(True)`<br/>`bytes(False)`|? | **str** |`int("12")`<br/>`int("fe", 16)`|`float("12.5")`|`"False" == "False"`<br />`bool("")` | `"Hello"`<br/>`"Привіт"`<br/>`'Hello'` | `"привіт".encode("UTF-8")`| `tuple("привіт")` | **bytes**| ? | ? | `bool(b"")`<br/>`bool(b"nonempty")` | `b'\xd0\x99\xd0\x9e!'.decode("UTF-8")` | `b"hello"` | `tuple(b'\xd0\x99\xd0\x9e!')` | **tuple**| ? | ? | `bool(())`<br/>`bool((1,2))` | `str((1,2,3))`<br/>`''.join(('h','e','l','l','o'))`'| `bytes((1,2,3,4,5))` | `(1, 2)`<br />`(5,)`<br />`()` ## Змінні типи (послідовності) list bytearray ## Складні типи dict set ## Все решта functions class object module generator ....