Learn and Learn

Learn And Learn - great place for tutorials, references and how-to

Python bool() function

bool() is a built-in function in python programming language which converts a value to boolean . Boolean values are only consist of true and false. True is represented as 1 and false represented as 0.
bool() function is a part of Python Built-in Functions (check list)

bool() Syntax

 

bool(n) Parameters

n – where n is an integer , string , empty sequence, empty mapping or special value (none).

 

bool() Return Value

bool() function returns true or false value.

 

bool() Compatibility

This function is available and compatible with both Python 2.x and 3.x

 

Example 1

When integer value is 0 bool() returns false

Return value: False

 

Example 2

When floating point value is 0.0 bool() returns false

Return value: False

 

Example 3

When long integer value is 0L bool() returns false

Return value: False

 

Example 4

When long integer value is 0L bool() returns false

Return value: False

 

Example 5

When complex number value is 0j in bool() returns false

Return value: False

 

Example 6

When String value is empty in bool() returns false

Return value: False

 

Example 7

When empty list in bool() returns false

Return value: False

LearnAndLearn.com © 2018 - All rights reserved