为什么 Python 中的 08 或 09 无效? [英] Why is 08 or 09 in Python invalid?
本文介绍了为什么 Python 中的 08 或 09 无效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Python 解释器中,08
和 09
似乎无效.示例:
如您所见,只有 08
和 09
似乎不起作用.这些是特殊值还是什么?
解决方案
带有前导零的数字被解释为八进制文字.所以 8 和 9 在八进制中是无效的.仅数字 0 到 7 有效.
在解释器中尝试:
<预><代码>>>>0119>>>01210>>>01311In the Python interpreter, 08
and 09
seem invalid. Example:
>>> 01
1
>>> 02
2
>>> 03
3
>>> 04
4
>>> 05
5
>>> 06
6
>>> 07
7
>>> 08
File "<stdin>", line 1
08
^
SyntaxError: invalid token
>>> 09
File "<stdin>", line 1
09
^
SyntaxError: invalid token
As you can see, only 08
and 09
don't seem to work. Are these special values or something?
解决方案
A number with a leading zero is interpreted as octal literal. So 8 and 9 are invalid in octal. Only digits 0 to 7 are valid.
Try in interpreter:
>>> 011
9
>>> 012
10
>>> 013
11
这篇关于为什么 Python 中的 08 或 09 无效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文