Operator perbandingan

Python untuk Pengguna MATLAB

Justin Kiggins

Product Manager

Menggunakan operator perbandingan

value = 0.967
threshold = 0.85

meets_criteria = value > threshold

print(meets_criteria)
True
Python untuk Pengguna MATLAB

Operator perbandingan

Perbandingan Python MATLAB
Sama dengan == ==
Tidak sama dengan != ~=
Lebih kecil dari < <
Lebih kecil/sama dengan <= <=
Lebih besar dari > >
Lebih besar/sama dengan >= >=
Python untuk Pengguna MATLAB

If

value = 0.967
threshold = 0.85

meets_criteria = value > threshold

if meets_criteria: print('PASS')
PASS
Python untuk Pengguna MATLAB

Else

value = 0.275
threshold = 0.85

meets_criteria = value > threshold

if meets_criteria: print('PASS') else: print('FAIL')
FAIL
Python untuk Pengguna MATLAB

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 untuk Pengguna MATLAB

Ayo berlatih!

Python untuk Pengguna MATLAB

Preparing Video For Download...