官术网_书友最值得收藏!

Logical operators

Logical operators are used to check different conditions and execute the code accordingly. For example, detecting a button interfaced to the Raspberry Pi's GPIO being pressed and executing a specific task as a consequence. Let's discuss the basic logical operators:

  • EQUAL: The EQUAL (==) operator is used to compare if two values are equal:
       >>>3==3 
True
>>>3==2
False
  • NOT EQUAL: The NOT EQUAL (!=) operator compares two values and returns True if they are not equal:
       >>>3!=2 
True
>>>2!=2
False
  • GREATER THAN: This operator (>) returns True if one value is greater than the other value:
       >>>3>2 
True
>>>2>3
False
  • LESS THAN: This operator compares two values and returns True if one value is smaller than the other:
       >>>2<3 
True
>>>3<2
False
  • GREATER THAN OR EQUAL TO (>=): This operator compares two values and returns True if one value is greater/bigger than or equal to the other value:
       >>>4>=3 
True
>>>3>=3
True
>>>2>=3
False
  • LESS THAN OR EQUAL TO (<=): This operator compares two values and returns True if one value is smaller than or equal to the other value:
       >>>2<=2 
True
>>>2<=3
True
>>>3<=2
False
主站蜘蛛池模板: 西平县| 比如县| 来安县| 海淀区| 嘉鱼县| 桐梓县| 菏泽市| 泰宁县| 怀化市| 东山县| 武邑县| 宁蒗| 沅陵县| 措勤县| 班玛县| 巴林右旗| 黔西| 清流县| 和静县| 山阴县| 融水| 吉木乃县| 昌乐县| 辛集市| 额济纳旗| 普陀区| 吐鲁番市| 云浮市| 盖州市| 渝北区| 怀宁县| 青阳县| 淄博市| 镇原县| 河曲县| 政和县| 泌阳县| 沧源| 夏河县| 武定县| 扎囊县|