The unofficial CircuitPython Reference

comparison operators

description

Comparison operators make a comparison between two variables or numbers and return a value of True or False. They are most frequently used in conditional statements.

syntax

OperatorNameDescription Example SyntaxExample Result
==equal tosee if operand one is equal to operand 2 return True or False1 == 2FALSE
!=not equal tosee if operand one is NOT equal to operand 2 return True or False1 != 2TRUE
>greater than see if operand 1 is greater than operand 2 return True or False 1 > 2FALSE
<less thansee if operand 1 is less than operand 2 return True or False1 < 2TRUE
>=greater or equalsee if operand 1 is greater than or equal to operand 2 return True or False 1 >= 2FALSE
<=less or equalsee if operand 1 is less than or equal to operand 2 return True or False 1 <= 2TRUE

methods

parameters

returns

example code

serial output:

see also: