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

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
主站蜘蛛池模板: 宁安市| 丰镇市| 营山县| 揭东县| 楚雄市| 定兴县| 河西区| 库尔勒市| 金山区| 枣强县| 喀喇沁旗| 塘沽区| 富平县| 阳朔县| 睢宁县| 斗六市| 泽普县| 明光市| 沭阳县| 台湾省| 墨玉县| 海口市| 平湖市| 彰化市| 章丘市| 神木县| 宿州市| 会东县| 罗源县| 文山县| 农安县| 邻水| 百色市| 深水埗区| 西乌珠穆沁旗| 乐都县| 枣强县| 辽阳市| 桃江县| 江川县| 专栏|