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

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
主站蜘蛛池模板: 周口市| 五莲县| 昔阳县| 娱乐| 禹州市| 当雄县| 泾川县| 拉孜县| 靖边县| 龙海市| 肇州县| 泽州县| 台安县| 海伦市| 克山县| 江西省| 项城市| 辉南县| 平阳县| 阿拉善左旗| 砀山县| 安庆市| 云林县| 上思县| 东宁县| 阿瓦提县| 富宁县| 封丘县| 景宁| 嘉义县| 盱眙县| 新巴尔虎左旗| 镇赉县| 庆阳市| 沁水县| 微山县| 横山县| 乐平市| 湟中县| 保靖县| 靖远县|