How can I make `bin(30)` return `00011110` instead of `0b11110`?

Viewed 75100

What does the "b" stand for in the output of bin(30): "0b11110"? Is there any way I can get rid of this "b"? How can I get the output of bin() to always return a standard 8 digit output?

7 Answers

You can use format in Python 2 or Python 3:

>> print( format(15, '08b') )
00001111

[]'s

You can use this too :

 bi=bin(n)[2:]

This will remove the '0b' portion of the returned value and you can use the output anywhere .

Related