Jämförelseoperatorer

Python för MATLAB-användare

Justin Kiggins

Product Manager

Använda jämförelseoperatorer

value = 0.967
threshold = 0.85

meets_criteria = value > threshold

print(meets_criteria)
True
Python för MATLAB-användare

Jämförelseoperatorerna

Jämförelse Python MATLAB
Lika med == ==
Inte lika med != ~=
Mindre än < <
Mindre än eller lika med <= <=
Större än > >
Större än eller lika med >= >=
Python för MATLAB-användare

If

value = 0.967
threshold = 0.85

meets_criteria = value > threshold

if meets_criteria: print('PASS')
PASS
Python för MATLAB-användare

Else

value = 0.275
threshold = 0.85

meets_criteria = value > threshold

if meets_criteria: print('PASS') else: print('FAIL')
FAIL
Python för MATLAB-användare

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! :(
Python för MATLAB-användare

Nu kör vi en övning!

Python för MATLAB-användare

Preparing Video For Download...