More about Python Boolean

Now we discuss Python boolean in detail. We shall discuss what are boolean. What is the use of these boolean in python, and much more.

Boolean

What are Boolean in Python

Now before discussing what are booleans in Python we should aware of word or term boolean that is use in the context of programming. Boolean is used when we have to know that our expression is true or false. We can evaluate any expression in an programming language and can check whether it is true or not you might know when we use comparison operator our compiler will give us answer or you can say output in True or False see below example:

print(200 > 100)
print(200 == 100)
print(2000 < 100)

Output

True
False
False

Most Values are True in Python How can we check

For example in our code any string, number or array is true when it is empty or 0 or empty respectively. Otherwise it will be false see below example:

print(bool("Codelikechamp.com"))
print(bool(12345678))
print(bool(["c++", "c#", "python"]))

Output

True
True
True
Boolean

Some Values are False in Python How can we check

print(bool(False))
print(bool(None))
print(bool(0))
print(bool(""))
print(bool(()))
print(bool([]))
print(bool({}))

Output

False
False
False
False
False
False
False

Link: https://Codelikechamp.com

Medium Link: Follow me on Medium

Linkedin Link: Follow me on Linkedin

🤞 Don’t miss any latest posts!

Please subscribe by joining our community for free and stay updated!!!

IF YOU HAVE ALREADY SUBSCRIBED JUST CLOSE THIS FORM !

Leave a Comment

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

Scroll to Top