All Posts

Python Data Structures

Python Data Structures

Python provides several built-in data structures that help you store and organize data efficiently. Understanding these structures is essential for effective programming in Python.

List

A list is an ordered, mutable collection that can hold elements of different types.

fruits = ["apple", "banana", "cherry"]

Tuple

A tuple is like a list, but it’s immutable (cannot be changed after creation).

coordinates = (10.5, 20.4)

Set

A set is an unordered collection of unique elements.

unique_numbers = {1, 2, 3, 4}

Dictionary

A dictionary stores data in key-value pairs.

person = {"name": "Alice", "age": 30}

String

Although primarily used for text, strings are also a sequence data structure in Python.

message = "Hello, World!"

Summary Table

Data Structure Ordered Mutable Duplicates Allowed
List Yes Yes Yes
Tuple Yes No Yes
Set No Yes No
Dictionary Keys: No
Values: N/A
Yes Keys: No
Values: Yes
String Yes No Yes

 

 

Python Tutorials

Python Tutorial on this website can be found at: