ใช้ relational operators ใน Python เปรียบเทียบตัวเลข (float และ int) ตัวดำเนินการเหล่านี้เปรียบเทียบค่าทั้งสองข้างและตัดสินความสัมพันธ์ สมมติ a=10, b=20
| Operator | Example |
|---|---|
| == | (a == b) is not true. |
| != | (a != b) is true. |
| > | (a > b) is not true. |
| < | (a < b) is true. |
| >= | (a >= b) is not true. |
| <= | (a <= b) is true. |
ตัวอย่าง
a = 10 b = 20 print(a == b) print(a != b) print(a > b) print(a < b) print(a >= b) print(a <= b)
ผลลัพธ์
False True False True False True