Data Structures in Python (With Examples):


Data structures are an important concept in Python programming, and Python provides a rich set of built-in data structure that makes it easy to work with and manipulate data.

The most common data structure in Python are lists, tuples, sets, and dictionaries. These data structures can be combined and nested to create more complex data structures.

If you want to get more information about Python Fundamentals you can visit here.

Here are some basic data structures in Python with a brief explanation:


A list is an ordered collection of values, which can be of any type. Lists are mutable, which means you can add, remove, and modify elements in the list.

my_list = [1, 2, 3, "four", 5.0]
my_list.append("six") #Here append function is used to enter element to list
# Output: [1, 3, 'four', 5.0, 'six']

In the above code new element “six” is appended to the list and “2” is removed from the list.


A tuple is an ordered collection of values, similar to a list. However, tuples are immutable, which means you cannot add, remove, or modify elements in the tuple.

my_tuple = (1, 2, 3, "four", 5.0)
# Output: (1, 2, 3, 'four', 5.0)


A set is an unordered collection of unique values. Sets are mutable, which means you can add and remove elements from the set.

As here you can see.

my_set = {1, 2, 3, "four", 5.0}
# Output: {1, 3, 'four', 5.0, 'six'}


A dictionary is an unordered collection of key-value pairs. Each key in the dictionary must be unique. Dictionaries are mutable, which means you can add, remove, and modify key-value pairs in the dictionary.

my_dict = {"name": "Alice", "age": 30, "city": "New York"}
my_dict["state"] = "NY"
del my_dict["city"] # del function is used to delete elements
# Output: {'name': 'Alice', 'age': 30, 'state': 'NY'}

These are some of the basic data structures in Python. There are other data structures available in Python, such as queues, stacks, and trees, which can be created using classes and objects.

If you want to learn more about python then subscribe to us to get the more latest information about Python.

Was this helpful?

Related Articles:

Recent Articles:

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x