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

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
主站蜘蛛池模板: 万盛区| 江口县| 西和县| 庆城县| 蒙阴县| 嘉峪关市| 博兴县| 平谷区| 德惠市| 隆昌县| 南召县| 托克逊县| 桐梓县| 色达县| 陆川县| 梁山县| 辛集市| 高安市| 平邑县| 常德市| 三明市| 大邑县| 林芝县| 麦盖提县| 阿克陶县| 鲁甸县| 子长县| 永城市| 五台县| 定兴县| 内乡县| 临城县| 墨江| 永福县| 永德县| 太原市| 芮城县| 云龙县| 城市| 西安市| 涡阳县|