What is Boolean in Python?

At this point, we see all basic things introduction, variable, and casting, and in the last article, we see what is python string in this article we learn about boolean in python. First, we learn what is boolean, Then evaluate value and variable, After all, last we see how Function can Return a Boolean.

What Is Boolean?

In any programming language boolean is a data type. In this data type, we have only two choices True or false. Boolean Algebra is the main logic or concept behind it.

Boolean values

When you do a program or In the program, You have to check Expression in a true or false scenario that Time you can use This Boolean concept. Every Expression must have Two answers either True or False. An example is given below,

print(20 > 40)
print(20 == 20)

Output Of Above Code is,

False
True

Evaluate Values and Variables

For evaluating any value here you can use bool() function, And give True Or False Value, Here Understand with example.

First of all we are try to evaluate string and number

print(bool("SMGPLAZA"))
print(bool(9898))

Output Of above code is both true

True
True

Evaluate two variable, Here first declare the variable then call those with bool() Function.

x = "SMGPLAZA"
y = 9898

print(bool(x))
print(bool(y))

Output Of above code is both true.

True
True

Which Value is True and Which are False?

Here Evaluation is true for String, Number with 0, List, Tuple, Set, Dictionary This all are True.

And False Is ( ), [ ], { }, ” “, the number 0, and the value None. And of course the value False evaluates to False.

We Are Understanding Both with One Simple Example.

""" True """
print(bool("SMGPLAZA"))
print(bool(123))
print(bool(["apple", "cherry", "banana"]))

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

Output Of this code is First 3 is True and Rest of that is False.

True
True
True
False
False
False
False
False
False

Functions can Return a Boolean

In python If you create a function and you want to return a value as true or false then you can use boolean like below,

def SMGPLAZA() :
  return True

print(SMGPLAZA())

Here we define function with no argument and just call it so that return true and print here.

True

For All python article, you have to follow this link, https://smgplaza.com/category/python/

Also visit this articles :-

If you have any doubts any suggestions or any query DM us one below Social media handles.

Our Social Media Handles:-

Instagram Handle :- https://www.instagram.com/smgplaza/

Twitter Handle :- https://twitter.com/smgplaza

Thank you so much for your support, you all are very valuable for us. You have to follow us using your mail id and also follow us on social media for more updates. We are one by one covering all topics of python and android both. If you have any query then comment me on the below comment box.