0% found this document useful (0 votes)
2 views3 pages

Quick Recap Capsule 2

The document provides an overview of lists and tuples in Python, highlighting their definitions, characteristics, and common operations. Lists are mutable collections created with square brackets, while tuples are immutable collections created with parentheses. It includes examples of list and tuple operations, as well as programming exercises for practical understanding.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Quick Recap Capsule 2

The document provides an overview of lists and tuples in Python, highlighting their definitions, characteristics, and common operations. Lists are mutable collections created with square brackets, while tuples are immutable collections created with parentheses. It includes examples of list and tuple operations, as well as programming exercises for practical understanding.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

QUICK RECAP CAPSULE 2:

Lists & Tuples in Python

Lists in Python

 A list is an ordered, mutable (changeable) collection of items.


 Created using square brackets [ ].
 Example:
 fruits = ["apple", "banana", "cherry"]

✅ Common List Operations

 Accessing elements: fruits[0] → "apple"


 Append: [Link]("mango")
 Insert: [Link](1, "orange")
 Extend: [Link](["grapes", "kiwi"])
 Sort: [Link]()
 Search: "banana" in fruits → True

🔹 Tuples in Python

 A tuple is an ordered, immutable (cannot be changed) collection of


items.
 Created using parentheses ( ).
 Example:
 numbers = (1, 2, 3, 4)

✅ Tuple Features

 Access elements: numbers[0] → 1


 Tuples cannot be changed → numbers[1] = 10 ❌
 Convert list → tuple: tuple([1, 2, 3])
 Convert tuple → list: list((1, 2, 3))
 Delete tuple: del numbers

  Define a list and give one example.


→ A list is a mutable collection of ordered elements.
Example: marks = [85, 90, 78].
  Define a tuple and give one example.
→ A tuple is an immutable collection of ordered elements.
Example: days = ("Mon", "Tue", "Wed").
  Write one difference between append() and extend().
→ append() adds a single element, extend() adds multiple elements
from another list.
 Write a program to create a list of 5 numbers and print their sum.

numbers = [10, 20, 30, 40, 50]


print("Sum:", sum(numbers))
# Output: Sum: 150

 Write a program to create a tuple of 4 fruits and print each element


using a loop.

fruits = ("apple", "banana", "mango", "orange")


for f in fruits:
print(f)

 Convert the tuple (1, 2, 3, 4) into a list and insert 5 at the end.

tup = (1, 2, 3, 4)
lst = list(tup)
[Link](5)
print(lst)
# Output: [1, 2, 3, 4, 5]
 Write a program to accept 5 student names in a list and sort them
alphabetically.

students = []
for i in range(5):
name = input("Enter student name: ")
[Link](name)
[Link]()
print("Sorted List:", students)

 A tuple contains marks of 5 students: (78, 85, 90, 67, 88). Write a
program to find the highest and lowest marks.

marks = (78, 85, 90, 67, 88)


print("Highest:", max(marks))
print("Lowest:", min(marks))

You might also like