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

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
主站蜘蛛池模板: 通榆县| 嘉黎县| 砀山县| 永康市| 保德县| 永昌县| 砚山县| 金寨县| 梅河口市| 汪清县| 龙岩市| 库伦旗| 龙泉市| 眉山市| 杨浦区| 临泉县| 娱乐| 光泽县| 东莞市| 宝坻区| 屏山县| 榆中县| 搜索| 灵宝市| 普格县| 炉霍县| 衡山县| 临朐县| 郴州市| 张家界市| 上栗县| 涡阳县| 吴桥县| 大化| 九龙县| 淮北市| 大兴区| 涪陵区| 东丰县| 金平| 定安县|