2

在 Python 3.8 中,是否有原因0000000003产生错误时有效?

>>> 000
0

03
  File "<stdin>", line 1
    03
     ^
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers
4

1 回答 1

0

是的。Python 的常量派生自 C,其中以 0 开头的整数被解释为八进制。因此,0377具有十进制值 255。随着时间的推移,Python 已更改为0o前缀,但 C 仍然允许使用0前缀。为了避免任何潜在的混淆,0前缀现在是一个语法错误。

于 2021-10-06T06:32:53.397 回答