I am using the python shell to figure out how the print command works in python.
When I type in
print 01
1
print 010
8
print 0100
64
print 030
24
What’s going on here? Is it just base 2? Why does the “one” in the second position print as 8? Shouldn’t it be 2 if it’s binary?
Starting a number with a zero marks it as octal in Python 2. This has been recognized as confusing, surprising and also inconsistent, as starting with 0x will mark it as hexadecimal. Therefore, in Python 3, starting with 0 is invalid, and you get octal by starting with 0o. You can also start with 0b to mark it as binary.
0x, 0o and 0b also works in Python 2.6 and Python 2.7.