Friday, March 13, 2026

Python Tutorial for Beginners: Data Structures

We have recently finished the chapter "Python Functions". Now our next chapter is "Data Structures". This is an important chapter because it helps us store and manage multiple values at once.

What is Data Structure?

We have seen variables that store a single value at a time. But what should we do when we want to store multiple values? Here, data structures provide an efficient way to store more than one value in Python. There are 4 types of main built-in data structures: List, Tuple, Sets, and Dictionaries. Each one has different features and use cases.

Python List

list is an ordered and mutable data structure that allows support duplicate value. It is denoted by square brackets [ ] to store values.

Example: 

numbers = [10, 20, 30, 40]
print(numbers)

If you want to access a value from a list, you must use its index number. In Python, the index number starts from 0.

numbers = [10, 20, 30, 40]
print(numbers[0])
print(numbers[2])

Add & Remove Elements
List is also mutable i.e we can add and remove any value or element.
numbers.append(50) #add value

numbers.remove(30) #remove value

Python Tuples

Tuples is an ordered and immutable data structure that allows duplicate value. It is denoted by small brackets ( ) to store values.

Example:

colors = ("red", "green", "blue")
print(colors)

If you want to access a value from a Tuples;

print(colors[0])

Adding and removing elements is not applicable in tuples because they are immutable, i.e., you cannot modify them.

Python Sets

Sets are an unordered list and a collection of unique items. This is the best suited for removing duplicate items.

numbers = (1, 1, 2, 3, 4, 4, 5)
print(numbers)
Output: (1, 2, 3, 4, 5)

Adding element: numbers.add(6) 

Python Dictionaries

Dictionaries store data in key-value pair. It is use curely bracket to manage element.

Quillix_tutorial = {
  "website": "Quillix", 
  "course":"Python", 
  "duration":"6month"
  }

To access element or value from dictionary:

print (Quillix_tutorial["course"])

To add new data:
Quillix_tutorial["chapter"] = "Data Structure"
print(Quillix_tutorial)

Comparision Table: List, Tuples, Sets and Dictionaries

Data StructureOrderedChangeableDuplicates
ListYesYesYes
TupleYesNoYes
SetNoYesNo
DictionaryYesYesKeys unique

Final Thoughts

Here is our next chapter: Python Data Structures. I hope you have successfully completed the previous chapter and practiced the examples as well. Please share this post with others too. Thank you for supporting and sharing our Python tutorials.

Keep reading! Our next chapter will be Python Strings.

Practice Your Code Below

🐍 Python Playground

No comments:

Post a Comment

Featured Post

What Is Artificial Intelligence (AI) ? – A Step-by-Step Guide

AI (Artificial Intelligence) is a rapidly growing technology in today's world, and you can see it whenever you browse or search for any ...