Boolean in Python

Boolean in Python

What is Boolean in Python?

Do you ever answer your friends like yes and no? That's it you know booleans, But here we will learn how to say that it is a python way. True and False with the capital 'T' and capital 'F' Boolean values are used where we need to compare some expressions in python. We can compare the lists,tuples,sets using(==) and(!=)operators to get booleans.


# true

# false

# false as order matters in list.

# false as order matters in tuples.

# true as order not matters in sets.

Booleans can be converted into strings and numbers using built-in(str) and(int) functions. simple remember True=1 & False=0

Strings and Numbers can also be converted to booleans using the built-in (bool) function.

In numbers only (0) converts to false remaining all are True.

In strings only empty string('') converts to false remaining all are True.

Booleans can also be added and multiplied by numbers. when we do so the Python converts the boolean value into its number represents and then does the arithmetic.