使用八进制数时令牌无效 [英] Invalid Token when using Octal numbers

查看:50
本文介绍了使用八进制数时令牌无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 python 的初学者,我试图在我的脚本中使用八进制数,但是当我尝试它时,它返回给我那个错误:

<预><代码>>>>一 = 010语法错误:令牌无效(<pyshell#0>,第 1 行)>>>01语法错误:无效标记(<pyshell#1>,第 1 行)

我的代码有问题吗?我正在使用 Python3(并阅读 Python 2.2 书籍)

解决方案

试试0o10,可能是python 3的原因,也可能是pyshell本身.

PEP 说,

<块引用>

现在必须指定八进制文字用前导0o"或0O"代替"0";

http://www.python.org/dev/peps/pep-3127/

I'm a beginner in python and I'm trying to use a octal number in my script, but when I try it, it returns me that error:

>>> a = 010
SyntaxError: invalid token (<pyshell#0>, line 1)
>>> 01
SyntaxError: invalid token (<pyshell#1>, line 1)

There's something wrong with my code? I'm using Python3 (and reading a python 2.2 book)

解决方案

Try 0o10, may be because of python 3, or pyshell itself.

PEP says,

octal literals must now be specified with a leading "0o" or "0O" instead of "0";

http://www.python.org/dev/peps/pep-3127/

这篇关于使用八进制数时令牌无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆