Bin() vs 0b


Just a really quick question:

What is the difference between bin() and 0b? When do you use both of these? And should you / can you use them at the same time?

Thanks in advance!


The bin() function is a tool for representing numbers in binary form. For instance, 0b1111 is the return value from bin(15). Both may be used, but for clarity and readability, be sure it makes sense.

Generally speaking, we don't think of numbers in their binary form, so using the function is one way to limit errors. How easy is it to find an error in a 32bit number representation? Not very. Binary numbers that are shifted, grow and shrink exponentially.

65536 is an easy number to read. "0b10000000000000000" is not,