Python int to binary string?
You can use the built-in bin()
function to convert an integer to a binary string in Python. Here is an example:
Output:
'0b101'
Watch a video course
Python - The Practical Guide
Note that the result will include the prefix '0b' indicating that the value is in binary representation. If you want to remove this prefix, you can use string slicing like this:
Output:
'101'
You can also use the format method to achieve the same
Output:
'101'