Categories: TutorialsUbuntu

Python bool() Function in Linux

Introduction

In Python, the bool() function is used to convert a value to a boolean value (True or False) to check the truth according to the standard.

If the object has a value of None, False or equal to 0, the bool() function will return false. Except for all of the above, the bool() function will return true.

The following article is a detailed guide on how to use the bool() function in Python as we go through the section below.

Example

x = []

print(bool(x))

y = 1

print(bool(y))

Output:

False

True

Definition

The bool() function can return 2 values: True and False.

If object is empty like (), [], {}, the function will return False.

The
Sponsored
syntax

bool(object)

Parameter Values:

object: any object. For example: number, string, list…

Sponsored

More example

Example 1: Basic bool() function

x = 1

y = 2

print(bool(x == y))

Output:

False

Example 2: Parity check program

def check(x):

return (bool(x % 2 == 0))

x = 4

if (check(x)):

print("Correct")

else:

print("Incorrect")

Output:

Correct

Conclusion

Hope you understand our tutorial on how to use the bool() function in Python.

Thanks for reading!

Ubuntu Server Admin

Recent Posts

Ubuntu 25.10 Beta Release is Available to Download

Ubuntu 25.10, code-name Questing Quokka, is now available for Beta testing! The developer team announced…

1 day ago

How to build an awesome cloud gaming platform with Anbox Cloud

Why cloud gaming? Cloud gaming is changing the way we play. Instead of buying expensive…

2 days ago

Dolphin Emulator 2509 now Emulates Cars 2 & Disney Infinity Smoothly

Dolphin, the free open-source GameCube and Wii game emulator, released new 2509 version today after…

2 days ago

GNOME 49 Officially Released with New Video Player & Document Viewer

GNOME developer team finally announced the 49 release of this popular Linux Desktop environment! If…

2 days ago

Ubuntu 25.10 (Questing Quokka) Beta released

The Ubuntu Release team is pleased to announce the Beta release of the Ubuntu 25.10…

2 days ago

Canonical achieves IEC 62443-4-1 compliance in Industrial Automation and Control Systems

Canonical is proud to announce it has achieved compliance with IEC 62443-4-1 for cybersecurity in…

3 days ago