Data Structures and Algorithms can be broadly classified into categories based on their complexity and usage. The two main types of data structures are : Primitive and Non-Primitive Data Structures. Primitive data types are the basic building blocks—like integers, floats, booleans, and strings—that store single values. Non-Primitive data types are more complex and can store multiple values or relationships between data. These are further divided into Built-in (like lists, sets, dictionaries) and User-Defined (like stacks, queues, trees, graphs).
A quick Graphical Representation of categorization of data types.
Primitive data structures in Python are the fundamental building blocks used to store and manage simple data values. They include types such as integers (int), floating-point numbers (float), strings (str), booleans (bool), and complex numbers (complex). These structures are immutable or mutable depending on the type and provide the basis for more complex data structures like lists, dictionaries, and sets. They are efficient, easy to use, and essential for performing basic operations, computations, and forming the foundation for algorithms and higher-level data manipulation in Python programs.
1Integer (int)
Integers, represented by the int data type in Python, are used to store whole numbers without any fractional or decimal parts. These can be positive, negative, or zero, making them one of the most fundamental data types in any programming language. Integers are the building blocks of mathematical operations and are widely used for tasks such as counting, indexing, iteration, and arithmetic calculations.
Python handles integers very efficiently and can represent numbers of virtually any size — from small counters to extremely large numeric values — without requiring special syntax or data type conversion. This is because Python automatically manages integer size based on the value, unlike languages that have fixed integer limits.
Integers are also used in control structures, loop counters, and data indexing, where numeric precision and simplicity are essential. They support a wide range of mathematical operators such as +, -, *, //, and %, allowing developers to perform quick calculations with ease.
Example :
Input:
|
Output:
|
The float data type in Python is used to represent real numbers — that is, numbers that contain a fractional or decimal component. Floats are essential in situations where precision and accuracy are required, such as scientific calculations, measurements, financial analysis, and statistical computations.
Unlike integers, which only store whole numbers, floats allow you to represent values like 3.14, -0.75, or 2.0. They are stored internally using a double-precision format, meaning they can handle very small or very large numbers efficiently. However, because of how floating-point arithmetic works at the binary level, slight rounding errors can sometimes occur — a common characteristic of all programming languages.
Floats are often used in mathematical formulas, simulations, or wherever division or areas typically involves float operations.
Example :
Input :
|
Output:
|
The bool data type in Python represents logical values — either True or False. Booleans are the foundation of decision-making in programming and play a crucial role in controlling the flow of execution within a program. They are commonly used in conditional statements (if, else, elif), loops, and comparisons, helping programs make logical choices based on certain conditions.
Booleans are often the result of comparison or logical operations. For example, expressions like 5 > 3, x == y, or status != 'inactive' return a Boolean value (True or False). These results can then determine whether a block of code should run or be skipped.
Python treats True as equivalent to 1 and False as equivalent to 0, which allows Booleans to integrate seamlessly into numerical operations and data analysis.
Example :
Input :
|
Output:
|
A string, represented by the str data type in Python, is a sequence of characters enclosed within single quotes (' ') or double quotes (" "). Strings can include letters, digits, symbols, or whitespace, making them one of the most versatile and widely used data types in programming.
Strings are primarily used for text manipulation, displaying messages, handling user input, and storing textual information such as names, addresses, or file paths. In Python, strings are immutable, meaning once created, their content cannot be changed directly. However, you can create modified versions using various built-in string methods such as .upper(), .lower(), .replace(), .split(), and .join().
Python also allows string concatenation using the + operator and formatting using f-strings or the .format() method, making text operations simple and powerful. Strings support indexing and slicing, enabling easy access to individual characters or substrings.
Example :
Input :
|
Output:
|
Top Tutorials
Related Articles