Python_Presentation
Python_Presentation
22CSE020 22CSE022
22CSE026
Python Lists: Ordered, Mutable Collections
Lists in Python are ordered collections. It is used to store multiple items in a single variable. Lists are mutable,
allowing modification after creation.
• Ordered sequences of elements : When we say that lists are ordered, it means that the elements have a defined
order, and that order will not change. If you add new items to a list, the new items will be placed at the end of
• the list. : The list is mutable, meaning that we can change, add, and remove elements in a list after it has been created.
Mutable
• Allow duplicate values : Since lists are indexed, lists can have items with the same value.
• Ordered sequences of elements : When we say that tuples are ordered, it means that the items have a defined
order, and that order will not change.
• Immutable : Tuples are unchangeable, meaning that we cannot change, add or remove items after the tuple has been cre
• Allow duplicate values : Since tuples are indexed, they can have items with the same value.
Example of tuple:
Python Sets: Unordered, Unique Collections
Sets are used to store multiple items in a single variable.
• Unordered : Set items can appear in a different order every time you use them, and cannot be referred to by index or key
• Unique : Sets cannot have two items with the same value.
• Mutable : In sets. we can add or remove elements after their creation, the individual elements within the set
cannot be changed directly.
• Key-value mappings : This operation allows us to expand the dictionary by adding new entries or modify the value of an e
• Mutable: values can be changed
• Unique keys required: Dictionaries cannot have two items with the same key.
Key-Value 1
Data is stored as pairs.
2 Mutable
Values can be updated.
Unique Keys 3
Each key must be unique in the dictionary.
Dictionary Methods:
Example of Dictionary:
List vs. Tuple vs. Set vs. Dictionary
Lists are ordered and mutable, while tuples are ordered and immutable. Sets are unordered collections of unique
elements. Dictionaries store key-value pairs.
Choose the appropriate data structure based on your needs. Consider mutability, order, and uniqueness when making your c