Python Programming PRACTICAL NO.8 ANSWERS
Python Programming PRACTICAL NO.8 ANSWERS
ir
eS
IX Conclusion:
Ans.
ad
Conclusion
efficiently. Understanding these functions makes list manipulation easier and more
effective in Python programming.
M
1.
ir
2.
eS
2) Describe various list functions.
ans/
ad
Various List Functions in Python
The pop() function in Python removes and returns an element from a list at a
specified index. If no index is given, it removes the last element by default.
Syntax:
ir
list_name.pop() # Removes the last element if index is not provided
eS
Example:
Key Points:
Ans.
● Purpose:Adds multiple elements from another iterable (list, tuple, set) to the
end of a list.
Syntax:
list1.extend(iterable)
●
Example:
ir
list1 = [1, 2, 3]
list1.extend([4, 5, 6])
●
eS
print(list1) # Output: [1, 2, 3, 4, 5, 6]
2. pop() Method
ad
● Purpose: Removes and returns an element from a list (default: last item).
Syntax:
list_name.pop(index) # Removes element at the given index
oh
●
Example:
M
●
Key Points:
Ans.
ir
Python Program to Find Common Items from Two Lists
eS
list1 = [1, 2, 3, 4, 5]
list2 = [4, 5, 6, 7, 8]
ad
# Find common elements using set intersection
Output:
Ans.
numbers = [5, 2, 9, 1, 7]
ir
print("Sorted List:", numbers)
eS
Output: