Python Glossary Русский

all Python 3Data typesterm

int

numbers

Arbitrary-precision integer. Accepts a string together with its numeric base: int('ff', 16) → 255.

Syntax

int([x]) | int(x, base)

The / operator always returns a float (5 / 2 → 2.5) — use // when you want an integer result. Also note that bool is a subclass of int, so True == 1, isinstance(True, int) is True, and True + True evaluates to 2.

Examples

x = 42  # обычное целое
y = -7  # отрицательное
n = int("123")  # из строки → 123
b = 0b1010  # двоичный → 10
h = 0xFF  # шестнадцатеричный → 255
big = 10 ** 100  # Python поддерживает big int без ограничений
print(int("FF", 16))  # → 255 (из строки с основанием)
print(int(3.99))  # → 3 (усечение, а не округление)

See also

Open in the full glossarydocs.python.orgReport an inaccuracy