On this page
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
- Includes
"0b"prefix: Useformat(n, "b")orf"{n:08b}"when you want bare or fixed-width bits.
REPL Inspect
help(bin)
Linked from
Related notes
- tuts/python3/__builtins__/__builtins__ Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/ascii Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/bool Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/chr Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/format Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/hex Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/oct Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__ links to this page; shared tags: #builtins
- tuts/python3/__builtins__/ord links to this page; shared tags: #builtins
- tuts/c/builtins shared tags: #builtins