Python bool()

In this post, we will see about Python bool() method.
Python bool() method returns two values either True or False.


Syntax

x(optional):It is object which you want to be evaluated.
If you do not pass any value to bool, it is evaluated to be False.


Return

It returns True or False.

Most objects can be cast to a boolean value. You should expect every standard object to evaluate to True unless it is either 0, None, False or an empty iterable (for example: “”, [], or {}).


Example

Let’s see a very simple example:

False

True

False

False

True

True

False

False

As you can see, bool returns False in case of 0, None, False or an empty iterable (for example: “”, [], or {}).

Leave a Reply

Your email address will not be published. Required fields are marked *