Python:无效的令牌
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/336181/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python: Invalid Token
提问by The.Anti.9
Some of you may recognize this as Project Euler's problem number 11. The one with the grid.
你们中的一些人可能认为这是欧拉计划的第 11 个问题。有网格的问题。
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?
为什么在逗号前抛出错误?
回答by Jeremy Ruten
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.
我认为当您以 0 开头的文字数字时,它会将其解释为八进制数,并且八进制数中不能有“8”。
回答by yairchu
Note that the "^" symbol in the error points exactly to the erroneous column. Together with the line number it points exactly on the digit 8. This can help lead you to what Jeremy suggested.
请注意,错误中的“^”符号正好指向错误的列。连同行号,它正好指向数字 8。这可以帮助您了解 Jeremy 的建议。
回答by maxp
Just remove leading zeros.
只需删除前导零。
First zero makes number octal.
第一个零使数字成为八进制。