Why does Python 3 allow “00” as a literal for 0 but not allow “01” as a literal for 1?

前端 未结 3 2031
情书的邮戳
情书的邮戳 2020-12-08 09:06

Why does Python 3 allow \"00\" as a literal for 0 but not allow \"01\" as a literal for 1? Is there a good reason? This inconsistency baffles me. (And we\'re talking about P

3条回答
  •  被撕碎了的回忆
    2020-12-08 09:23

    Python2 used the leading zero to specify octal numbers:

    >>> 010
    8
    

    To avoid this (misleading?) behaviour, Python3 requires explicit prefixes 0b, 0o, 0x:

    >>> 0o10
    8
    

提交回复
热议问题