Python Lecture 2 Data Structures in Python
Python Lecture 2 Data Structures in Python
organizing and storing data so that they can be accessed and worked with efficiently. Python
provides a variety of built-in data structures, such as lists, tuples, sets, and dictionaries, each with its
Lists
Lists in Python are ordered collections that are changeable and allow duplicate members. They are
created by placing all the items (elements) inside square brackets [ ], separated by commas. Lists
support various methods such as append(), remove(), and sort() that help in manipulating the data.
Tuples
Tuples are similar to lists but are immutable, meaning they cannot be changed after creation. They
are written with round brackets ( ). Tuples are faster than lists and are used to protect the data from
being changed.
Sets
Sets are unordered collections of unique elements. They are defined by values separated by
commas inside curly braces { }. Sets are useful for removing duplicate values from a list or tuple and
Introduction to Python Programming
Dictionaries
Dictionaries in Python are unordered collections of data in a key:value pair form. They are written
with curly brackets, and they have keys and values. Dictionaries are optimized to retrieve values