Sometimes, we want to convert an int to binary string with Python .
In this article, we’ll look at how to convert an int to binary string with Python.
How to convert an int to binary string with Python?
To convert an int to binary string with Python, we can use the string’s format
method.
For instance, we write:
b = "{0:b}".format(37)
print(b)
We use the {0:b}
formatting code to convert an int to a binary string.
Therefore, b
is 100101, which is 37 in binary.
Conclusion
To convert an int to binary string with Python, we can use the string’s format
method.