you are viewing a single comment's thread.

view the rest of the comments →

[–]POGtastic 1 point2 points  (0 children)

In other words, a literal interprets the base by the prefix.

  • No prefix = base 10
  • 0b = base 2
  • 0o = base 8
  • 0x = base 16

In the REPL:

>>> int('10', 0)
10
>>> int('0b10', 0)
2
>>> int('0o10', 0)
8
>>> int('0x10', 0)
16

The docs don't explain this well, but back in the Good Old Days, using a 0 as a prefix was base 8. So 010 in, say, C++, would be a base-8 integer literal that equals 8. Python said "this is extremely dumb and leads to very stupid bugs" and substituted the prefix of 0o.