Comparison operators

Python for MATLAB Users

Justin Kiggins

Product Manager

Using comparison operators

value = 0.967
threshold = 0.85

meets_criteria = value > threshold

print(meets_criteria)
True
Python for MATLAB Users

The comparison operators

Comparison Python MATLAB
Equal == ==
Not equal != ~=
Less than < <
Less than or equal <= <=
Greater than > >
Greater than or equal >= >=
Python for MATLAB Users

If

value = 0.967
threshold = 0.85

meets_criteria = value > threshold

if meets_criteria: print('PASS')
PASS
Python for MATLAB Users

Else

value = 0.275
threshold = 0.85

meets_criteria = value > threshold

if meets_criteria: print('PASS') else: print('FAIL')
FAIL
Python for MATLAB Users

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 for MATLAB Users

Let's practice

Python for MATLAB Users

Preparing Video For Download...