0% found this document useful (0 votes)
3 views

Python_Presentation

The document introduces four built-in data types in Python: Lists, Tuples, Sets, and Dictionaries, each with distinct characteristics. Lists are ordered and mutable, Tuples are ordered and immutable, Sets are unordered and unique, while Dictionaries store data as key-value pairs and are mutable. The document emphasizes the importance of choosing the appropriate data structure based on mutability, order, and uniqueness.

Uploaded by

tabmoy76
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Python_Presentation

The document introduces four built-in data types in Python: Lists, Tuples, Sets, and Dictionaries, each with distinct characteristics. Lists are ordered and mutable, Tuples are ordered and immutable, Sets are unordered and unique, while Dictionaries store data as key-value pairs and are mutable. The document emphasizes the importance of choosing the appropriate data structure based on mutability, order, and uniqueness.

Uploaded by

tabmoy76
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Introduction to Python :

Lists, Tuples, Sets, and


Dictionaries
There are 4 built-in data types in Python used to store collections
of data : List, ​Tuple​, ​Set​, and ​Dictionary​, all with different qualities
and usage.

22CSE019 22CSE021 22CSE023

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 Mutable Duplicates Allowed


Elements maintain their order. Items can be modified. Lists can store the same value
multiple times.
List Methods:
Python has a set of built-in methods that you can use on lists/arrays.
Example of List:
Python Tuples: Ordered, Immutable
Collections
Tuples are similar to lists but with a key difference.

• 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.

Ordered Immutable Duplicates Allowed


Elements maintain their order. Once created, tuples cannot be Tuples can store the same value
modified. multiple times.
Tuple Methods:
Python has a set of built-in methods that you can use on tuple

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.

Unordered Unique Mutable


Elements have no specific order. Sets contain no duplicates. Items cannot be changed
Set Methods:
Example of Sets:
Python Dictionaries: Key-Value Pairs
Dictionaries store data as key-value pairs. Each key must be unique, and it maps to a corresponding value.
Dictionaries are mutable, which can be changed. Dictionaries are useful for storing related data.

• 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

Feature List Tuple Set Dictionary

Ordered Yes Yes No Yes

Changeable Yes No Yes Yes

Duplicates Allowed Allowed Not Allowed Keys Not Allowed,


Values Allowed

You might also like