Knowledge Base‎ > ‎Programming‎ > ‎Python‎ > ‎Python Reference‎ > ‎

relational-operators


Related:

 Examples

 
 == (equality)
> (greater than)
>= (greater than or equal to)
!= (inequality)
< (less than)
<= (less than or equal to)

 Description        

 
Performs a test between two variables, values or expressions.Work as you would expect from your experience with them in math or other classes. Evaluate to either True or False.

See interpreter session below for more information.

Note: if you these operators with numbers that are stored as strings you will get strange results. See last few lines of interpreter session.


 Syntax

 
 

 Parameters

 

 Interpreter

 Python 2.6.1 (r261:67517, Dec  4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> 1 == 1

True

>>> 1 > 2

False

>>> 1 >= 1

True

>>> n = 10

>>> n != 10

False

>>> n == 10

True

>>> 2 < 4

True

>>> 2 <= 2

True

>>>




Comments