# What is Boolean in Python?

Jul 15, 2020

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``

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/