ตัวดำเนินการเปรียบเทียบ

Python สำหรับผู้ใช้ MATLAB

Justin Kiggins

Product Manager

การใช้ตัวดำเนินการเปรียบเทียบ

value = 0.967
threshold = 0.85

meets_criteria = value > threshold

print(meets_criteria)
True
Python สำหรับผู้ใช้ MATLAB

ตัวดำเนินการเปรียบเทียบ

การเปรียบเทียบ Python MATLAB
เท่ากับ == ==
ไม่เท่ากับ != ~=
น้อยกว่า < <
น้อยกว่าหรือเท่ากับ <= <=
มากกว่า > >
มากกว่าหรือเท่ากับ >= >=
Python สำหรับผู้ใช้ MATLAB

If

value = 0.967
threshold = 0.85

meets_criteria = value > threshold

if meets_criteria: print('PASS')
PASS
Python สำหรับผู้ใช้ MATLAB

Else

value = 0.275
threshold = 0.85

meets_criteria = value > threshold

if meets_criteria: print('PASS') else: print('FAIL')
FAIL
Python สำหรับผู้ใช้ 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 สำหรับผู้ใช้ MATLAB

มาฝึกกันเถอะ!

Python สำหรับผู้ใช้ MATLAB

Preparing Video For Download...