Learn Python

Data Types In Python

Data Type is basically the type of data a variable holds. For example if the variable store a number then the variable data type will be a integer.

Python has many built-in data types, Following is the list of all data types in python:

Data TypeExampleDescription
int30Integer (whole number)
float3.15Floating-point number (decimal)
str“Hello”String (sequence of characters)
boolTrueBoolean (True or False)
list[1, “apple”, True]List (ordered collection)
tuple(2, “banana”, False)Tuple (immutable ordered list)
dict{“name”: “Alice”, 28}Dictionary (key-value pairs)
set{1, 2, 3}Set (unordered collection of unique elements)
NoneTypeNoneRepresents absence of a value

Now let’s see each data type one by one.

1. Integer

age = 25

Integer type represents whole numbers.

2. Float

size = 2.5

Float type represents decimal or floating-point numbers

3. String

name = "John Doe"

String type represents sequences of characters enclosed in single or double quotes

4. Boolean

is_adult = True
is_teen = False


Boolean type represents either True or False.

5. List

grades = [90, 85, 92, 88]

A list is an ordered collection that can contain elements of different data types.

6. Tuple

coordinates = (3, 5)

Similar to a list but immutable (cannot be modified after creation).

7. Dictionary

person = {"name": "Alice", "age": 28, "is_student": False}

Dictionary is an unordered collection of key-value pairs.

8. Set

unique_numbers = {1, 2, 3, 4, 5}

Unordered collection of unique elements.

9. None

no_value = None

Represents the absence of a value or a null value.

Checking Data Type Of A Variable

score = 90
name = "Jason"
is_injured = False

In python we can check the data type of a variable using the type() function, In the function you need to pass the variable you want to check and the pass the type() function in print() function to print the data type.

So this was everything you needed to know about variable data types in python.