Python在if语句中引发了"="上的SyntaxError

Zac*_*dry -5 python

我正在编写一个程序,它接受用户输入并将其与不同的命令字符串进行比较.当我尝试运行该程序时,我得到一个SyntaxError关于该行if method = 'addition':,IDLE突出显示为=红色.

num1 = input('Enter your first value: ')
num2 = input('Enter your second value: ')
method = input('Which method will you be using? ')

if method = 'addition':
    solveFor = num1 + num2
elif method = 'subtraction':
    solveFor = num1 - num2
else:
    print("Please enter 'addition' or 'subtraction'")
Run Code Online (Sandbox Code Playgroud)

Bre*_*arn 7

Python中的等式比较运算符是==. =是一个为变量赋值的语句.

您的代码有许多其他错误(与不确定的名字开始num1,num2坐在那里一开始什么都不做).您应该阅读Python教程以了解Python语法的基础知识.