June 2017
Beginner
352 pages
8h 39m
English
Boolean values are commonly produced by Python’s relational operators which can be used for comparing objects. Two of the most widely used relational operators are Python's equality and inequality tests, which actually test for equivalence or inequivalence of values. That is, two objects are equivalent if one could use used in place of the other. We'll learn more about the notion of object equivalence later in the book. For now, we'll compare simple integers.
Let's start by assigning — or binding — a value to a variable g:
>>> g = 20
We test for equality with == as shown in the following command:
>>> g == 20True>>> g == 13False
For inequality we use !=:
>>> g != 20False>>> g != 13True
Read now
Unlock full access