布尔运算符

Python 金融进阶

Kennedy Behrman

Data Engineer, Author, Founder

布尔逻辑

乔治·布尔

Python 金融进阶

什么是布尔运算?

  1. and
  2. or
  3. not
Python 金融进阶

对象求值

计算为 False

  • 常量:

    • False
    • None
  • 数值零:

    • 0
    • 0.0
  • 长度为零

    • ""
    • []
    • {}

计算为 True

  • 其他几乎所有值
Python 金融进阶

AND 运算符

True and True
True
True and False
False
Python 金融进阶

OR 运算符

False or True
True
True or True
True
False or False
False
Python 金融进阶

短路。

is_current() and is_investment()
False
is_current() or is_investment()
True
Python 金融进阶

NOT 运算符

not True
False
not False
True
Python 金融进阶

NOT 的运算顺序

True == False
False
not True == False
True
Python 金融进阶

对象求值

"CUSIP" and True
True
Python 金融进阶

对象求值

[] or False
False
Python 金融进阶

对象求值

not {}
True
Python 金融进阶

返回对象

"Federal" and "State"
"State"
[] and "State"
[]
Python 金融进阶

返回对象。

13 or "account number"
13
0.0 or {"balance": 2200}
{"balance": 2200}
Python 金融进阶

Passons à la pratique !

Python 金融进阶

Preparing Video For Download...