On this page
  1. bin
  2. Import & Availability
  3. Overview & Signature
  4. Usage
  5. Gotchas
  6. REPL Inspect

bin

Prev: ascii | Up: __builtins__ | Next: bool
Rel: ascii, chr, format, hex, oct
Ref: docs.python.org — bin
Tags: #public #python3 #builtins


Import & Availability

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

Overview & Signature

bin(number, /)

Return the binary representation of an integer.

Usage

assert bin(10) == "0b1010"
assert bin(-10) == "-0b1010"
assert f"{10:08b}" == "00001010"   # bare zero-padded binary without 0b prefix

Gotchas

REPL Inspect

help(bin)

Linked from

Related notes