Python:无效的令牌 [英] Python: Invalid Token
本文介绍了Python:无效的令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你们中的一些人可能认为这是欧拉计划的第 11 个问题.有网格的问题.
我试图在一个大型多维数组中复制网格,但它给了我一个语法错误,我不知道为什么
grid = [[ 08, 02, 22, 97, 38, 15, 00, 40, 00, 75, 04, 05, 07, 78, 52, 12, 50, 77, 91, 08 ],[ 49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 04, 56, 62, 00 ],[ 81, 49, 31, 73, 55, 79, 14, 29, 93, 71, 40, 67, 53, 88, 30, 03, 49, 13, 36, 65 ],...
我收到此错误:
<前>文件D:\development\Python\ProjectEuler\p11.py",第 3 行[ 08, 02, 22, 97, 38, 15, 00, 40, 00, 75, 04, 05, 07, 78, 52, 12, 50, 77, 91, 08 ],^ 语法错误:无效的令牌为什么在逗号前抛出错误?
解决方案
我认为当您以 0 开头的文字数字时,它会将其解释为八进制数,而八进制数中不能有 '8'.
Some of you may recognize this as Project Euler's problem number 11. The one with the grid.
I'm trying to replicate the grid in a large multidimensional array, But it's giving me a syntax error and i'm not sure why
grid = [
[ 08, 02, 22, 97, 38, 15, 00, 40, 00, 75, 04, 05, 07, 78, 52, 12, 50, 77, 91, 08 ],
[ 49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 04, 56, 62, 00 ],
[ 81, 49, 31, 73, 55, 79, 14, 29, 93, 71, 40, 67, 53, 88, 30, 03, 49, 13, 36, 65 ],
...
And I get this error:
File "D:\development\Python\ProjectEuler\p11.py", line 3 [ 08, 02, 22, 97, 38, 15, 00, 40, 00, 75, 04, 05, 07, 78, 52, 12, 50, 77, 91 , 08 ], ^ SyntaxError: invalid token
Why is it throwing an error before the comma?
解决方案
I think when you start a literal number with a 0, it interprets it as an octal number and you can't have an '8' in an octal number.
这篇关于Python:无效的令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文