Boolean operators

Intermediate Python for Finance

Kennedy Behrman

Data Engineer, Author, Founder

Boolean logic

George Boole

Intermediate Python for Finance

What are Boolean operations?

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

Object evaluation

Evaluates as False

  • Constants:

    • False
    • None
  • Numeric zero:

    • 0
    • 0.0
  • Length of zero

    • ""
    • []
    • {}

Evaluates as True

  • Almost everything else
Intermediate Python for Finance

The AND operator

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

The OR operator

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

Short circuit.

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

The NOT operator

not True
False
not False
True
Intermediate Python for Finance

Order of operations with NOT

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

Object evaluation

"CUSIP" and True
True
Intermediate Python for Finance

Object evaluation

[] or False
False
Intermediate Python for Finance

Object evaluation

not {}
True
Intermediate Python for Finance

Returning objects

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

Returning objects.

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

Let's practice!

Intermediate Python for Finance

Preparing Video For Download...