Table of contents
1.
Introduction
2.
What are Primitive Data Types in Python?
2.1.
1. Integer (int)
2.1.1.
Example
2.2.
2. Float (float)
2.2.1.
Example
2.3.
3. Boolean (bool)
2.3.1.
Example
2.4.
4. String (str)
2.4.1.
Example
2.5.
5. Complex (complex)
2.5.1.
Example
3.
Examples of Primitive Data Types
3.1.
Example
4.
Differences Between Primitive and Non-Primitive Data Types in Python
5.
When to Use Primitive Data Types in Python?
6.
Frequently Asked Questions
6.1.
Why are primitive data types important in Python?
6.2.
Can we change the value of a primitive data type in Python?
6.3.
How do you check the data type of a variable in Python?
7.
Conclusion
Last Updated: Mar 11, 2025
Easy

Primitive Data Types in Python

Author Rahul Singh
0 upvote

Introduction

Primitive data types in Python are the basic building blocks used to store simple values. These include integers, floats, strings, booleans, and NoneType. Each type serves a specific purpose, such as performing arithmetic operations, representing text, or handling logical conditions. Since Python is dynamically typed, variables do not need explicit type declarations. 

In this article, you will learn about different primitive data types, their properties, and how they are used in Python programming.

What are Primitive Data Types in Python?

Primitive data types are the basic building blocks of data in Python. These data types hold simple values and are stored in memory efficiently. Python has several primitive data types:

  1. Integer (int) – Represents whole numbers
     
  2. Float (float) – Represents decimal numbers
     
  3. Boolean (bool) – Represents True or False values
     
  4. String (str) – Represents sequences of characters
     
  5. Complex (complex) – Represents complex numbers
     

Each of these data types has specific characteristics and use cases, which we will discuss with examples.

1. Integer (int)

Integers are whole numbers that can be positive, negative, or zero.

Example

num = 10
print(type(num)) 
print(num)       
You can also try this code with Online Python Compiler
Run Code


Output: 

<class 'int'>
10

2. Float (float)

Floats are numbers with decimal points or in exponential form.

Example

pi_value = 3.14159
print(type(pi_value)) 
print(pi_value)       
You can also try this code with Online Python Compiler
Run Code


Output

<class 'float'>
3.14159

3. Boolean (bool)

Boolean values represent truth values: True or False.

Example

is_python_fun = True
print(type(is_python_fun)) 
print(is_python_fun)   
You can also try this code with Online Python Compiler
Run Code


Output: 

<class 'bool'>
True

4. String (str)

Strings are sequences of characters enclosed in single, double, or triple quotes.

Example

message = "Hello, Python!"
print(type(message))  
print(message)       
You can also try this code with Online Python Compiler
Run Code


Output

<class 'str'>
Hello, Python!

5. Complex (complex)

Complex numbers consist of a real and imaginary part.

Example

complex_num = 2 + 3j
print(type(complex_num))  
print(complex_num)        
You can also try this code with Online Python Compiler
Run Code

 

Output: 

<class 'complex'>
(2+3j)

Examples of Primitive Data Types

To better understand how these data types work, let’s look at a practical example combining multiple primitive data types.

Example

age = 20                # Integer
height = 5.7            # Float
is_student = True       # Boolean
name = "John Doe"       # String
complex_num = 4 + 5j    # Complex

print(f"Name: {name}, Age: {age}, Height: {height}, Student: {is_student}, Complex Number: {complex_num}")
You can also try this code with Online Python Compiler
Run Code

 

Output:

Name: John Doe, Age: 20, Height: 5.7, Student: True, Complex Number: (4+5j)

Differences Between Primitive and Non-Primitive Data Types in Python

FeaturePrimitive Data TypesNon-Primitive Data Types
Stores Simple ValuesYesNo
MutabilityImmutable (unchangeable)Mutable (changeable)
Examplesint, float, bool, str, complexlist, tuple, dictionary, set
Memory UsageLessMore

Non-primitive types (like lists, tuples, dictionaries) allow storing multiple values and are more complex in structure.

When to Use Primitive Data Types in Python?

Primitive data types are useful in various scenarios:

  • Integer: When working with countable values, such as loop counters and index positions.
     
  • Float: When precision is required, like in scientific calculations and measurements.
     
  • Boolean: When dealing with conditional logic, such as decision-making in programs.
     
  • String: When handling text, such as names, messages, or file paths.
     
  • Complex: When working with mathematical computations that involve imaginary numbers.
     

Using primitive data types ensures efficient memory usage and better performance in simple calculations and logical operations.

Frequently Asked Questions

Why are primitive data types important in Python?

Primitive data types form the foundation of any Python program. They allow the storage of simple values, making them essential for performing basic operations and calculations.

Can we change the value of a primitive data type in Python?

No, primitive data types are immutable, meaning their value cannot be changed after assignment. However, you can assign a new value to the variable.

How do you check the data type of a variable in Python?

You can use the type() function to check the data type of any variable. 

Conclusion

In this article, we discussed primitive data types in Python, which include integers, floats, strings, booleans, and NoneType. These fundamental data types form the building blocks of Python programming, allowing efficient data storage and manipulation. Understanding primitive types is essential for writing optimized, error-free, and scalable Python applications.

Live masterclass