In this article, we will go over the essential data types in Python. Before we get started, if you don’t know how to write comments, please go through the following article: Write Comments in Python.

In Python, variables are objects, data types are the classes, and these variables are the instances of these classes. There are different kinds of data types in Python that specify what kind of values can be assigned to a variable.  We don’t need to declare the datatypes while assigning variables, Python being a dynamic programming language, will do that automatically

Text Type

String (str)

Definition: A string is identified as a continuous set of characters wrapped in quotation marks. Python allows either a pair of single or double quotes. Strings are an immutable sequence data type, i.e., each time one makes any changes to a string, an entirely new string object is created.

You can either go for single quotes or double quotes, but you should be consistent with it in the entire program.

You can also perform various actions on Strings

Numeric Types

In Python, there are 3 numeric data types – Integer, Float, and Complex. Integer and Float being the most used datatype.

Integers (int)

Definition: Any whole number can be classified as an Integer; sometimes it is addressed as an int. There is no limit on how long the integer value can be.

Float (float)

Definition: Any real number along with a decimal can be classified as a Float number. 12 is an integer, but 12.0 is a float.

Complex (complex)

Definition: Complex numbers are written in the form x + yj, where x is the real part and y is the imaginary part.

We don’t need to declare the datatypes while assigning variables, Python being a dynamic language, will do that automatically. When you enter a number without a decimal, Python will treat it as an integer, and when you enter a number with a decimal, then Python will treat it as a floating number. We can assign numbers to variables directly,

Boolean Type

Bool (bool)

Definition: A boolean data type can have one of the following two values: True or False. We can get Boolean (bool) output on basic math operations:

Sequence Types

List (list)

DefinitionA list contains items separated by commas and enclosed within square brackets []. Lists are almost similar to arrays in C. One difference is that all the items belonging to a list can be of different data types.

Each value inside a list is called an item, Lists are a very flexible data type because they are mutable, which means items can be added, deleted, or updated in a list. We can make a list of similar data types,

We can print them out by calling the print function. Additionally, we can also make a list of different data types.

Tuple (tuple)

DefinitionSimilar to lists, tuples are also used to group data of the same or different data types, but they immutable ordered sequence of items, i.e., like a list, we can’t update or delete items of a tuple. Tuples are enclosed in parentheses (). A tuple looks like:

Range (range)

Definition: A sequence of numbers generated from a start to an end (not including the end). Commonly used in loops.

Mapping Type

Dictionary (dict)

Definition: A Dictionary is an unordered pair of keys and values. It is used to store related data. The dictionary is heavily optimized for storing data and retrieving it from keys. It is enclosed in curly braces {}, and values can be assigned and accessed using square brackets[]. A dictionary looks like this :

Apart from curly braces, there is a colon (:) in the dictionary. The word to the left of the colon is Key, and the word to the right is the Value of that key. We can use the key to retrieve the data, but not the other way around. To retrieve data from the dictionary, we need to pass the key in square brackets[] like this,

Don’t forget to wrap the keys in either single or double quotes. A large dictionary can look something like this:

Each key-value pair is separated by a comma(,). We can retrieve all the keys and values like this:

To Print specific value we need to pass the key in square brackets like this:

Set Types

set

Definition: Unordered collection of unique items.

Duplicates are removed automatically:

frozenset

Definition: Immutable version of set.

Binary Types

bytes

Definition: An immutable sequence of bytes (8-bit values from 0 to 255). Used when you need an unchangeable sequence of binary data—such as reading data from a file or sending over a network.

bytearray

Definition:A mutable sequence of bytes. You can modify its content after creation. Ideal when you need to change individual bytes after creation (e.g., working with a mutable buffer or image processing).

memoryview

Definition:A memory-efficient view object that allows you to access the internal data of binary objects (like bytes, bytearray) without copying. Useful when working with large datasets or for high-performance computing where copying data is expensive.

None Type

NoneType

Definition: Represents the absence of a value or a null value. Use Case: To initialize variables before assignment, To signal “no result” or “empty” return, As a default value for function arguments

Next Recommended Article: How To Use String Formatting In Python

Data Types In Python

Leave a Comment