Booleans

Introduction to Booleans and data types

In this lesson you will learn what Booleans are. We will also talk about data types and the built-in type function.


In the last sections, we worked with text data and numbers. In doing so, we implicitly used two fundamental data types in Python.

We used strings str to store text, and integers int to store whole numbers.

If you want to know the type of a specific value, you can use the built-in function type:

# text data text = 'Hello World' print(type(text)) # whole number num = 123 print(type(num))
Python
Output

The output indicates that text is a string str and num is an integer int.

An integer int is the type for a whole number. Once a number has a decimal place, its type is a floating-point number float:

# number with decimal place num = 1.1 print(type(num))
Python
Output

Another Python data type is the Boolean bool.

Booleans simply indicate if something is true or false.

A Boolean can have only one of two possible values: True or False.

Just like with integers or strings, you can assign a Boolean to a variable:

is_active = False # print the type of is Active: print(type(is_active)) # print the value of is Active: print(is_active)
Python
Output

The variable name is_active is quite typical for a variable that has a Boolean value. Simply by the name of the variable, you know that it represents a state that is either true or false.


What will be the output?

a = '1' print(type(a))
Python

What will be the output?

a = 1 print(type(a))
Python

What will be the output?

a = 1.05 print(type(a))
Python

What will be the output?

a = True print(type(a))
Python