比较运算符

面向 MATLAB 用户的 Python

Justin Kiggins

Product Manager

使用比较运算符

value = 0.967
threshold = 0.85

meets_criteria = value > threshold

print(meets_criteria)
True
面向 MATLAB 用户的 Python

比较运算符一览

比较 Python MATLAB
等于 == ==
不等于 != ~=
小于 < <
小于等于 <= <=
大于 > >
大于等于 >= >=
面向 MATLAB 用户的 Python

If(如果)

value = 0.967
threshold = 0.85

meets_criteria = value > threshold

if meets_criteria: print('PASS')
PASS
面向 MATLAB 用户的 Python

Else(否则)

value = 0.275
threshold = 0.85

meets_criteria = value > threshold

if meets_criteria: print('PASS') else: print('FAIL')
FAIL
面向 MATLAB 用户的 Python

Else if(否则如果)

porridge_temperature = 74.6

if porridge_temperature > 130: print('Too hot! :(') elif porridge_temperature < 110: print('Too cold! :(') else: print('Just right :D')
Too cold! :(
面向 MATLAB 用户的 Python

开始练习

面向 MATLAB 用户的 Python

Preparing Video For Download...