if在函数定义中的语法错误

时间:2017-09-27 01:28:15

标签: python function if-statement

我有这段代码:

def rho(switch,y,h):
    if switch=1:
        return 1.255
    if switch=2:
        return 1.255*np.exp(-y/h)

显然if语句有语法错误,我无法弄清楚它是什么。

1 个答案:

答案 0 :(得分:0)

def rho(switch,y,h):
    if switch == 1:
        return 1.255
    if switch == 2:
        return 1.255*np.exp(-y/h)

==代替=语句中的if

相关问题