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

Python Module 2 (2 Part 2) PPT

The document covers the concepts of mutable and immutable data types in Python, including lists, tuples, dictionaries, and sets. It details various operations, methods, and characteristics of each data type, emphasizing their functionalities and differences. Additionally, it provides references for further reading on Python programming.

Uploaded by

sathyanainar2007
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)
14 views

Python Module 2 (2 Part 2) PPT

The document covers the concepts of mutable and immutable data types in Python, including lists, tuples, dictionaries, and sets. It details various operations, methods, and characteristics of each data type, emphasizing their functionalities and differences. Additionally, it provides references for further reading on Python programming.

Uploaded by

sathyanainar2007
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/ 24

23CSI201- Problem

Solving using Python


Programming
Module – II
Topic: List, Tuple, Dictionaries, Set

1
Course Outcomes

2
Mutable & Immutable Data Types in Python

Data Type Mutable Immutable

list ✅ Yes ❌ No

tuple ❌ No ✅ Yes

dict ✅ Yes ❌ No

set ✅ Yes ❌ No

str ❌ No ✅ Yes

int, float, boolean ❌ No ✅ Yes

3
List Operations

4
List Slicing

5
List Methods

6
Looping Through a List

7
Tuples
• A tuple is an immutable sequence of
elements.
• Once created, the items in a tuple cannot be
changed (no add, remove, or update).

8
Tuple Assignment
• assign multiple variables from a tuple

9
• return tuples from functions:

10
Indexing & Slicing

11
Tuple Methods
Method Description
Returns the number of times x appears
.count(x)

.index(x) Returns the index of the first occurrence of x

12
Dictionaries in Python
• A dictionary is a mutable collection of key-
value pairs.

13
Dictionary Operations

14
Iterating Through a Dictionary

15
Common Dictionary Methods
Method Description

Returns value for key or default if key not


.get(key, default)
found

.keys() Returns all keys

Returns key-value pairs


.items()

.update(dict2) Adds or updates from another dictionary

.values() Returns all values

.pop(key) Removes a key and returns its value

.clear() Removes all items

16
17
Sets in Python
• A set is an unordered, mutable, collection
of unique elements

18
Operations on Sets

19
Frozen Set
• A frozenset is an immutable version of a
set.

20
Common Set Methods
Method Description
.add(x) Adds element x
.remove(x) Removes x, raises error if not found
.discard(x) Removes x if present, no error if absent
.pop() Removes and returns a random element
.clear() Removes all elements
.update(other_set) Adds elements from another set

21
22
References
• Textbooks:
• T1. Allen B. Downey, “Think Python: How to Think like a Computer Scientist”,
2nd Edition, O’Reilly Publishers, 2016.
• T2. Karl Beecher, “Computational Thinking: A Beginner’s Guide to Problem-
Solving and programming”, 1st Edition, BCS Learning & Development Limited,
2017.
• Reference Book(s):
• R1. Paul Deitel and Harvey Deitel, “Python for Programmers”, Pearson
Education, 1st Edition, 2021.
• R2. G Venkatesh and Madhavan Mukund, “Computational Thinking: A Primer
for Programmers and Data Scientists”, 1st Edition, Notion Press, 2021.
• R3. Eric Matthes, “Python Crash Course, A Hands – on Project Based
Introduction to Programming”, 2nd Edition, No Starch Press, 2019

23
Thank you!!

24

You might also like