Boolean operators

Python ระดับกลางสำหรับการเงิน

Kennedy Behrman

Data Engineer, Author, Founder

Boolean logic

George Boole

Python ระดับกลางสำหรับการเงิน

Boolean operations คืออะไร?

  1. and
  2. or
  3. not
Python ระดับกลางสำหรับการเงิน

การประเมินค่าออบเจกต์

ประเมินเป็น False

  • ค่าคงที่:

    • False
    • None
  • ศูนย์เชิงตัวเลข:

    • 0
    • 0.0
  • ความยาวเป็นศูนย์

    • ""
    • []
    • {}

ประเมินเป็น True

  • เกือบทุกอย่างนอกจากนี้
Python ระดับกลางสำหรับการเงิน

AND operator

True and True
True
True and False
False
Python ระดับกลางสำหรับการเงิน

OR operator

False or True
True
True or True
True
False or False
False
Python ระดับกลางสำหรับการเงิน

Short circuit.

is_current() and is_investment()
False
is_current() or is_investment()
True
Python ระดับกลางสำหรับการเงิน

NOT operator

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 ระดับกลางสำหรับการเงิน

มาฝึกกันเถอะ!

Python ระดับกลางสำหรับการเงิน

Preparing Video For Download...