snippetpythonCritical
Convert int to binary string in Python
Viewed 0 times
convertintpythonbinarystring
Problem
How do I convert an integer into a binary string in Python?
37 → '100101'Solution
Python's string format method can take a format spec.
Format spec docs for Python 2
Format spec docs for Python 3
>>> "{0:b}".format(37)
'100101'Format spec docs for Python 2
Format spec docs for Python 3
Code Snippets
>>> "{0:b}".format(37)
'100101'Context
Stack Overflow Q#699866, score: 1115
Revisions (0)
No revisions yet.