How to Use bool() Function in PythonPython Basics


The bool() function returns the boolean value of a specified object.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

print("bool(0):  ", bool(0))
print("bool(1):  ", bool(1))
print("bool(2):  ", bool(2))
print("bool(3):  ", bool(3))
Output:

bool(0):   False
bool(1):   True
bool(2):   True
bool(3):   True

Syntax

bool(x)

Parameters

x–The parameters to be converted.

Return Value

It returns the boolean value of a specified object.

© 2024 Cheerlearn.com, all rights reserved. Privacy Policy | Contact Us