Introduction-to-Tuples-in-Python
Introduction-to-Tuples-in-Python
Tuples in Python
Welcome to our exploration of tuples in Python! In this
presentation, we'll cover the key features of tuples, compare
them with lists, and explore essential commands for working
with them.
Tuples and Lists
Tuples and lists are both used to store collections of data.
Tuples are immutable, meaning they cannot be changed,
while lists are mutable, allowing for modifications.
Tuples Lists
Order matters, cannot be Order matters, can be
changed. changed.
Comparison: Tuples vs.
Lists
Understanding the differences between tuples and lists is key to
choosing the right data structure for your needs.
4 sorted() 5 count()
Returns a sorted list from a tuple. Counts the occurrences of a specific element
in a tuple.
Code Example
Let's put our knowledge of tuple commands into practice with a code example.
my_tuple = (1, 2, 3, 4, 3)
print(min(my_tuple)) # Output: 1
print(max(my_tuple)) # Output: 4
print(sum(my_tuple)) # Output: 13
print(sorted(my_tuple)) # Output: [1, 2, 3, 3, 4]
print(my_tuple.count(3)) # Output: 2
Quiz Time!
Let's test your understanding of tuples with some multiple-choice questions!
• (A) 2
• (B) 4
• (C) 8
• (D) 6
Answer: A
Quiz Time!
Let's test your understanding of tuples with some multiple-choice questions!
Answer: B
Quiz Time!
Let's test your understanding of tuples with some multiple-choice questions!