Chapter 2 Operators, Truthy and Falsy Values
- Operators: constructs that can manipulate the value of operands
ex: 4+5=9, 4&5 ⇒ operands, + ⇒ operator
Types of operators
- Arithmetic operators: + - * / % ** (return a number)
- Assignment operators: =, +=, -=, *=, /=, **=
- Membership operators
- Comparison operators: ==, !=, >, <, >=, <= (return a boolean value)
- Logical operators (return a boolean value)
- Bitwise operators
- Identity operators: 少用到(不講)
Truthy and Falsy Values in Python
- In a Boolean context, almost all Python objects can be evaluated to be either True or False.
⇒ logical operator: 3 and 9, 3 is not a boolean, but it is applied in a boolean context. Thus, 3 will be evaluated to be either True or False.
- condition if(…) then ⇒ boolean context
- 被當成True的object : Truthy values / 被當成False的object: Falsy values (只需要記得Falsy objects)