Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 4. Python Objects > Standard Type Operators

4.5. Standard Type Operators

4.5.1. Value Comparison

Comparison operators are used to determine equality of two data values between members of the same type. These comparison operators are supported for all built-in types. Comparisons yield true or false values, based on the validity of the comparison expression. Python chooses to interpret these values as the plain integers 0 and 1 for false and true, respectively, meaning that each comparison will result in one of those two possible values. A list of Python's value comparison operators is given in Table 4.1.

Table 4.1. Standard Type Value Comparison Operators
operatorfunction
expr1 < expr2expr1 is less than expr2
expr1 > expr2expr1 is greater than expr2
expr1 <= expr2expr1 is less than or equal to expr2
expr1 >= expr2expr1 is greater than or equal to expr2
expr1 == expr2expr1 is equal to expr2
expr1 != expr2expr1 is not equal to expr2 (C-style)
expr1 <> expr2expr1 is not equal to expr2 (ABC/Pascal-style)[a]


[a] This “not equals” sign will slowly be phased out. Use != instead.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial