python - Odd sytax error in python: Invalid Syntax
问题描述
So for whatever reason I keep getting a syntax error and I can't seem to figure out why. When I comment out the line that is giving me the error it propagates through, but when I put the troublesome bit in a new file it carries through and I'm not seeing anything wrong above or below in all of the code syntactically.
def removeBlock(pos, blocks):
return blocks[pos] -= 1
def addBlock(pos, blocks):
return blocks[pos] += 1
def left(pos):
return pos -= 1
def right(pos):
return pos += 1
def done():
return "quit"
actions = {
"P": removeBlock,
"D": addBlock,
"L": left,
"R": right,
"X": done
}
The error is this:
SyntaxError: invalid syntax
it appears on the second line of this code.
解决方案
Python-=
运算符不提供返回值。也用于+=
等。
尝试:
def removeBlock(pos, blocks):
blocks[pos] -= 1
return blocks[pos]
或者你的意思是不改变块?
def removeBlock(pos, blocks):
return blocks[pos] - 1
推荐阅读
- python - 根据来自另一列 Python 的总数从另一个 csv 中选择值
- xcode - Xcode watch 模拟器核心数据文件位置
- python - Python:有效地比较非常大的 CSV 中的列
- scala - 如何在不使用 spark 的情况下从 AWS EMR 内部读取 S3 存储桶中的文本文件
- java - Java Eclipse将图像上传到包内的图像文件夹
- java - 在 Spring boot 中使用两个执行器运行并行作业
- api - YouTube 数据 API OAuth 2.0 - 响应范围参数抛出 403
- sql - 近两年的SQL拉取数据
- flutter - 如何在 Flutter 中获取 iOS 的 APNs 令牌以进行推送通知?
- c - 如何使用 fscanf 读取带分隔符的文件?