Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.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语法错误:无法分配给运算符_Python_Python 3.x_Syntax Error - Fatal编程技术网

Python语法错误:无法分配给运算符

Python语法错误:无法分配给运算符,python,python-3.x,syntax-error,Python,Python 3.x,Syntax Error,以下Python脚本引发语法错误: def main(number, number2, equation): if equation == 1: number + number2 = answer SyntaxError:cannotassign to operator是引发的错误。请帮助。您必须按此方向将(=)操作(number+number2)分配给变量应答 answer = number + number2 变量名在右侧而值、表达式、对象等在左侧在python中

以下Python脚本引发语法错误:

def main(number, number2, equation):
    if equation == 1:
        number + number2 = answer
SyntaxError:cannotassign to operator
是引发的错误。请帮助。

您必须按此方向将(
=
)操作(
number+number2
)分配给变量
应答

answer = number + number2

变量名在右侧而值、表达式、对象等在左侧

在python中,您可以将变量设置为等于其结果,而不是将结果设置为等于变量。 那么你把它放在哪里了

number+number2=答案
你需要做什么

answer=number+number2

由于您所做的是使number和number2之和等于答案,这是不可能的

很抱歉,我没有在代码中添加“代码外观”,我是一个傻瓜。您希望代码做什么?该语句对python无效。变量必须位于左侧,表达式必须位于右侧。欲了解更多信息,嘿@noobie,欢迎来到SO。祝贺您在学习Python方面所做的努力。坚持下去。语句-
number+number2=answer
无效。这是因为赋值运算符(=)将右侧值赋值给左侧。顺便说一句,不要因为落选而气馁。继续学习。