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 not operator flips the condition.

And Operator

  • The and operator combines two conditions.

Or Operator

  • The or operator 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:
    1. Condition: A Boolean expression or logical test.
    2. True Block: Code executed when the condition is true.
    3. 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