- 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.
- ArchiCAD 19:The Definitive Guide
- Instant Raspberry Pi Gaming
- Practical Ansible 2
- 平面設計初步
- Windows 8應用開發實戰
- Hands-On Linux for Architects
- Microsoft System Center Confi guration Manager
- Salesforce Advanced Administrator Certification Guide
- Dreamweaver+Photoshop+Flash+Fireworks網站建設與網頁設計完全實用
- AMK伺服控制系統原理及應用
- Mastering Predictive Analytics with scikit:learn and TensorFlow
- 精通ROS機器人編程(原書第2版)
- Windows 7來了
- 教育創新與創新人才:信息技術人才培養改革之路(四)
- 特征工程入門與實踐