Python - Документация

int (целые числа)

a = 10          # целое число
b = -256        # отрицательное целое
c = 0b1010      # двоичное число (10)
d = 0o12        # восьмеричное число (10)
e = 0xAF        # шестнадцатеричное число (175)

float (вещественные числа)

x = 3.14        # обычное число с плавающей точкой
y = -0.001      # отрицательное число
z = 1.2e3       # экспоненциальная запись (1200.0)

complex (комплексные числа)

c1 = 2 + 3j     # комплексное число
c2 = complex(1, -2)  # альтернативный способ создания

str (строки)

text1 = 'Hello'     # одинарные кавычки
text2 = "World"     # двойные кавычки
text3 = '''Многострочный
текст'''
text4 = f"Имя: {name}"  # f-строка
text5 = r'C:\path'    # сырая строка
is_true = True
is_false = False

list (списки)

numbers = [1, 2, 3, 4, 5]
mixed = [1, 'text', 3.14]

tuple (кортежи)

point = (10, 20)
colors = ('red', 'green', 'blue')

dict (словари)

person = {'name': 'Анна', 'age': 25}
settings = dict(theme='dark', font_size=14)

set (множества)

unique_numbers = {1, 2, 3, 4, 5}
letters = set('hello')  # {'e', 'h', 'l', 'o'}
bytes
data = b'Hello'
binary = bytes([65, 66, 67])  # ABC в байтах
bytearray
arr = bytearray(b'Hello')
arr[0] = 72  # можно изменять
memoryview
mem = memoryview(b'Hello')
NoneType
result = None
Ellipsis
ellipsis = ...

# Преобразование типов

num = int('123')        # 123
float_num = float('3.14')  # 3.14
text = str(123)         # '123'

# Проверка типа

isinstance(10, int)     # True
type('Hello') == str    # True

# Математические операции

a = 5 + 3              # 8
b = 10 / 2             # 5.0
c = 2 ** 3             # 8

# Операции со строками

text = 'Hello' + 'World'  # 'HelloWorld'
length = len(text)       # 10

# Работа со списками

numbers = [1, 2, 3]
numbers.append(4)       # [1, 2, 3, 4]

# Работа со словарями

person = {'name': 'Анна'}
person['age'] = 25      # {'name': 'Анна', 'age': 25}
(VotingAchievement.uuid == nomination_id) if nomination_id else True
~ VotingAchievement.uuid
nominations = await self._session.execute(
  select(VotingAchievement).where(
    ~VotingAchievement.is_deleted,
    VotingAchievement.is_published,
    (VotingAchievement.uuid == nomination_id) if nomination_id else True,
  ).order_by(VotingAchievement.position).options(
    selectinload(VotingAchievement.icon), selectinload(VotingAchievement.preview)
  )
)
 
for nomination in nominations.scalars().all():
  ...
result = []
for nomination in nominations.scalars().all():
  query = select(
    ExponentVotesAggregation.uuid,
    ExponentVotesAggregation.title_ru,
    ExponentVotesAggregation.title_en,
    func.sum(ExponentVotesAggregation.count).label("count")
  ).where(
    ExponentVotesAggregation.created_at >= since,
    ExponentVotesAggregation.created_at <= till,
    ExponentVotesAggregation.nomination_id == nomination.uuid,
  ).group_by(
    ExponentVotesAggregation.uuid,
    ExponentVotesAggregation.title_ru,
    ExponentVotesAggregation.title_en,
  ).order_by(desc(text("count")))
 
  exponents = await self._session.execute(
    query
  )
 
  result.append((nomination, exponents.all(),))