On this page
  1. int
  2. Import & Availability
  3. Overview & Signature
  4. Common Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

int

Prev: input | Up: __builtins__ | Next: isinstance
Rel: bool, float, complex, str, bytes
Ref: docs.python.org — int
Tags: #public #python3 #builtins


Import & Availability

# Built-in (available globally without import)
from builtins import int

Overview & Signature

int([x]) -> integer

int(x, base=10) -> integer Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating-point

Common Methods & Attributes

Usage

assert int("42") == 42
assert int("ff", 16) == 255
assert int("0b1010", 0) == 10   # base=0 auto-detects 0b/0o/0x prefixes
assert int(-3.9) == -3          # truncates toward zero

Gotchas

REPL Inspect

help(int)

Linked from

Related notes