Booleans and Conditionals
Booleans
- Booleans represent two values: True and False.
- Example:
my hair color is black: True
Relational Operators
- Equal to:
a = b - Not equal to:
a != b - Greater than:
a > b - Less than:
a < b - Greater than or equal to:
a >= b - Less than or equal to:
a <= b
Not Operator
- The
notoperator flips the condition.
And Operator
- The
andoperator combines two conditions.
Or Operator
- The
oroperator returns True if at least one condition is true.
Conditionals
- Condition statements are fundamental in programming and logic.
- They control the program’s flow based on certain conditions or criteria.
- A condition statement typically has three parts:
- Condition: A Boolean expression or logical test.
- True Block: Code executed when the condition is true.
- False Block (optional): Code executed when the condition is false.
Example
```python x = 10 if x > 5: print(“x is greater than 5”) # True block else: print(“x is not greater than 5”) # False block