Booleans and Operators

What is a Boolean?

A Boolean is a data type that can be either True or False. It's often the result of comparisons or logic.

Loading...
Output:

Comparison Operators

Compare two values using these operators:

OperatorNameExample
==Equal to5 == 5
!=Not equal5 != 3
>Greater than5 > 3
<Less than2 < 1
>=Greater or equal5 >= 5
<=Less or equal4 <= 3

Logical Operators

Logical operators let you combine multiple Boolean expressions. Try the examples below and predict whether they will evaluate to True or False. Then run the code to check your answers.

  • and – True only if both conditions are True
  • or – True if at least one condition is True
  • not – Reverses the Boolean value

🔹 Try this:

Predict the result of each line, then run the code to check if you're right:

Loading...
Output:

Truthy and Falsy Values

Some values evaluate to False:

  • 0, "", [], None → Falsy
  • Any non-empty or non-zero value → Truthy
Loading...
Output:

Other Operators

These are helpful in comparisons:

Loading...
Output:

Practice Exercise

🔹 What will each of these print?

Loading...
Output:

Practical Use Cases of Booleans

Booleans are used in real-world logic checks, conditionals, and flows:

Voting Eligibility

Loading...
Output:

Login Check

Loading...
Output:

Membership

Loading...
Output:

Input Validation

Loading...
Output:

Game Over Flag

Loading...
Output:

Need Help?

Ask the AI if you need help understanding or want to dive deeper in any topic