布林運算子

Intermediate Python for Finance

Kennedy Behrman

Data Engineer, Author, Founder

布林邏輯

George Boole

Intermediate Python for Finance

什麼是布林運算?

  1. and
  2. or
  3. not
Intermediate Python for Finance

物件的布林值

評估為 False

  • 常數:

    • False
    • None
  • 數值為 0:

    • 0
    • 0.0
  • 長度為 0

    • ""
    • []
    • {}

評估為 True

  • 幾乎其他所有情況
Intermediate Python for Finance

AND 運算子

True and True
True
True and False
False
Intermediate Python for Finance

OR 運算子

False or True
True
True or True
True
False or False
False
Intermediate Python for Finance

短路運算

is_current() and is_investment()
False
is_current() or is_investment()
True
Intermediate Python for Finance

NOT 運算子

not True
False
not False
True
Intermediate Python for Finance

NOT 的運算順序

True == False
False
not True == False
True
Intermediate Python for Finance

物件的布林值

"CUSIP" and True
True
Intermediate Python for Finance

物件的布林值

[] or False
False
Intermediate Python for Finance

物件的布林值

not {}
True
Intermediate Python for Finance

回傳物件

"Federal" and "State"
"State"
[] and "State"
[]
Intermediate Python for Finance

回傳物件。

13 or "account number"
13
0.0 or {"balance": 2200}
{"balance": 2200}
Intermediate Python for Finance

一起來練習吧!

Intermediate Python for Finance

Preparing Video For Download...