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

Relational operators

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 == 20
True
>>> g == 13
False

For inequality we use !=:

>>> g != 20
False
>>> g != 13
True
主站蜘蛛池模板: 承德县| 兰坪| 绵阳市| 嘉峪关市| 遂昌县| 长武县| 财经| 平安县| 乐陵市| 定结县| 麻江县| 五指山市| 新河县| 五指山市| 阿城市| 马公市| 黎城县| 永和县| 甘南县| 乳山市| 祁阳县| 万山特区| 临高县| SHOW| 卫辉市| 丹凤县| 新余市| 通道| 称多县| 普宁市| 班戈县| 天峻县| 大姚县| 湘潭县| 临沭县| 博野县| 台南县| 渝中区| 宿州市| 克什克腾旗| 疏附县|