Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 创建字典时出现无效令牌错误_Python 2.7_Dictionary - Fatal编程技术网

Python 2.7 创建字典时出现无效令牌错误

Python 2.7 创建字典时出现无效令牌错误,python-2.7,dictionary,Python 2.7,Dictionary,嗨,我在文本文件中有两组列,第一列是yyyy mm dd,第二列是降水。我只想提取4月到8月的降水量值。为了得到这个结果,我将行拆分,并从第1列中只提取月份。然后尝试为月份和降水量创建字典,并使用if语句匹配月份,并在空数组中追加相应的降水量值 执行此操作时,在下面的代码中,我的if语句在month==08时出现了一个“invalid token”错误: 代码: 任何帮助/指导都将不胜感激!谢谢,您不需要左边的零来比较数字 你可以更换你的电脑 if (month==04 or month==05

嗨,我在文本文件中有两组列,第一列是yyyy mm dd,第二列是降水。我只想提取4月到8月的降水量值。为了得到这个结果,我将行拆分,并从第1列中只提取月份。然后尝试为月份和降水量创建字典,并使用if语句匹配月份,并在空数组中追加相应的降水量值

执行此操作时,在下面的代码中,我的if语句在month==08时出现了一个“invalid token”错误:

代码:


任何帮助/指导都将不胜感激!谢谢,

您不需要左边的零来比较数字

你可以更换你的电脑

if (month==04 or month==05 or month==06 or month==07 or month==08):

根据答案,前面的零将数字转换为八进制,从而导致语法错误,因为
08
不是有效的八进制表示形式

if (month==04 or month==05 or month==06 or month==07 or month==08):
if month in (4,5,6,7,8):