Toán tử so sánh

Python cho người dùng MATLAB

Justin Kiggins

Product Manager

Dùng toán tử so sánh

value = 0.967
threshold = 0.85

meets_criteria = value > threshold

print(meets_criteria)
True
Python cho người dùng MATLAB

Các toán tử so sánh

So sánh Python MATLAB
Bằng == ==
Khác != ~=
Nhỏ hơn < <
Nhỏ hơn hoặc bằng <= <=
Lớn hơn > >
Lớn hơn hoặc bằng >= >=
Python cho người dùng MATLAB

If

value = 0.967
threshold = 0.85

meets_criteria = value > threshold

if meets_criteria: print('PASS')
PASS
Python cho người dùng MATLAB

Else

value = 0.275
threshold = 0.85

meets_criteria = value > threshold

if meets_criteria: print('PASS') else: print('FAIL')
FAIL
Python cho người dùng 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 cho người dùng MATLAB

Ayo berlatih!

Python cho người dùng MATLAB

Preparing Video For Download...