Site Title

🧠 Boolean Definition + Example

Boolean Logic


🌟 What is a Boolean?

A Boolean is a data type that can only have two possible values:

These values are used to answer questions like:


💡 Why are Booleans Important?

Booleans allow programs to make decisions! For example, you can use Booleans to check:


🐍 Boolean Examples in Python

Let’s look at some simple examples and explain each line:

# Example 1: Simple Boolean assignment
is_sunny = True

Explanation:

# Example 2: Boolean from a comparison
is_adult = 18 >= 18

Explanation:

# Example 3: Using Booleans in an if statement
age = 16
if age >= 18:
    print("You are an adult.")
else:
    print("You are not an adult.")

Explanation:

# Example 4: Boolean operators
is_raining = False
is_cold = True
if is_raining or is_cold:
    print("Bring a jacket!")

Explanation:


🎯 Summary

Booleans are everywhere in programming, and understanding them is key to writing effective code!