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

  • Practical Data Wrangling
  • Allan Visochek
  • 269字
  • 2021-07-02 15:16:09

Booleans

The Boolean data type has two, and only two, possible values, namely, True and False. In Python, you can produce a Boolean value by writing either True or False, starting with a capital T or F respectively:

>> True
>> False

Boolean values can be combined using bitwise operators:

  • The and operator yields True if the value on the left and the value on the right are both True
  • The or operator yields True if at least one of the items on the left or right is True

The following are some examples using bitwise operators:

>> True and True
>> True and False
>> True or False
>> False or False

Logical operators can be used to produce Boolean values from other data types by comparing values:

  • The == operator yields True if the values on either side are equal
  • The > operator yields True if value to the left is greater than the value to the right
  • The < operator yields True if the value to the right is greater than the value to the left

The following are some examples using logical operators:

>> 1 == 2
>> 1 == 1
>> 1 < 2
>> 1 < 0
>> 1 > 2
>> 2 > 1
>> "abc" == "abc"
>> "abc" == "cba"

Boolean values are good to make decisions within computer programs. You will see this when I introduce if statements later in the chapter. They are also good to store simple yes/no data entries, such as whether a particular individual lives in New York or whether a transaction has been completed.

主站蜘蛛池模板: 井陉县| 武乡县| 县级市| 九龙城区| 福贡县| 漳州市| 兰西县| 瑞昌市| 旬阳县| 井陉县| 鹰潭市| 宁远县| 合江县| 巴林左旗| 南丹县| 山阴县| 柳江县| 崇州市| 黄龙县| 广元市| 汕头市| 衡山县| 博乐市| 杭州市| 太保市| 大理市| 雷山县| 泉州市| 大厂| 巴楚县| 全椒县| 无锡市| 望谟县| 清流县| 吐鲁番市| 睢宁县| 阿图什市| 当涂县| 会宁县| 文成县| 马尔康县|