0
0
Pythonprogramming~5 mins

Boolean values (True and False) in Python

Choose your learning style9 modes available
Introduction

Boolean values help us decide between two choices: yes or no, true or false.

Checking if a light is on or off.
Deciding if a user is logged in or not.
Testing if a number is bigger than another.
Verifying if a door is locked or unlocked.
Syntax
Python
True
False

Boolean values always start with a capital letter in Python.

They represent the idea of yes/no or on/off in programs.

Examples
Here, we say it is raining (True) and not sunny (False).
Python
is_raining = True
is_sunny = False
If the light is on (True), we print a message.
Python
light_on = True
if light_on:
    print("The room is bright")
Sample Program

This program checks if you are hungry. If yes (True), it suggests eating.

Python
is_hungry = True
if is_hungry:
    print("Time to eat!")
else:
    print("Not hungry now.")
OutputSuccess
Important Notes

Boolean values are often used in conditions to control what the program does.

Remember, True and False are special words in Python, not strings.

Summary

Boolean values are True or False.

They help programs make decisions.

Use them to check conditions simply.