为什么python中的00100 = 64?

use*_*514 2 python int

为什么,像在下面的python代码中,00100相同64

>>> i = 00100
>>> i
64
>>> type(00100)
<type 'int'>
>>> str(00100)
'64'
>>> str("00100")
'00100'
>>> int(str("00100"))
100
>>> 
Run Code Online (Sandbox Code Playgroud)

n00*_*00b 9

它是一个八进制值,因为前导零

http://www.translatorscafe.com/cafe/units-converter/numbers/calculator/octal-to-decimal/

^计算器(很难总结)

  • 顺便说一句,请注意,在Python 3中,这将是一个语法错误,因为八进制文字的语法已经改变.请参阅http://stackoverflow.com/questions/1837874/invalid-token-when-using-octal-numbers (7认同)