Discuss / Python / 为啥if a = 0:会报错SyntaxError:invalid syntax(无效语句)

为啥if a = 0:会报错SyntaxError:invalid syntax(无效语句)

Topic source

import math

def quadratic(a,b,c):

if a = 0:
    print('二元方程式a不能为零')
if b * b - 4 * a * c >= 0:
    x1 = (-b + math.sqrt(b * b - 4 * a * c))/2 * a
    x2 = (-b - math.sqrt(b * b - 4 * a * c))/2 * a
    return x1,x2
else:
    print('二元次方程式不成立!')

print(quadratic(3,4,1)) print(quadratic(1,3,-4))

为啥if a = 0:会提示这个,如下:

SyntaxError:invalid syntax(无效语句)

廖雪峰

#2 Created at ... [Delete] [Delete and Lock User]

if a==0:


  • 1

Reply