Vergelijkingsoperatoren

Python voor MATLAB-gebruikers

Justin Kiggins

Product Manager

Vergelijkingsoperatoren gebruiken

value = 0.967
threshold = 0.85

meets_criteria = value > threshold

print(meets_criteria)
True
Python voor MATLAB-gebruikers

De vergelijkingsoperatoren

Vergelijking Python MATLAB
Gelijk == ==
Ongelijk != ~=
Kleiner dan < <
Kleiner dan of gelijk <= <=
Groter dan > >
Groter dan of gelijk >= >=
Python voor MATLAB-gebruikers

If

value = 0.967
threshold = 0.85

meets_criteria = value > threshold

if meets_criteria: print('PASS')
PASS
Python voor MATLAB-gebruikers

Else

value = 0.275
threshold = 0.85

meets_criteria = value > threshold

if meets_criteria: print('PASS') else: print('FAIL')
FAIL
Python voor MATLAB-gebruikers

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 voor MATLAB-gebruikers

Laten we oefenen!

Python voor MATLAB-gebruikers

Preparing Video For Download...