Exp4 Quest
Exp4 Quest
4A
Aim: Write programs to understand Different List and Tuple operations using Built-in functions
Software: Python
Theory : A List is a mutable, ordered collection of elements in Python whose Elements can be of
different data types. They are Defined using square brackets []. List Supports dynamic resizing,
adding, and removing elements.
A Tuple is an immutable, ordered collection of elements in Python whose Elements can be of
different data types. They are Defined using parentheses (). Once a tuple is created, its elements
cannot be added, removed, or modified
Different Operations on List and Tuple using Built-in Functions:
1)Length of List or Tuple (len()): len(my_list) returns the number of elements in the list or tuple.
2)Adding Elements (append()): my_list.append(element) adds the specified element to the end of
the list.
3)Inserting Elements (insert()):my_list.insert(index, element) inserts the element at the specified
index in the list.
4)Removing Elements (remove()): my_list.remove(element) removes the first occurrence of the
specified element from the list.
5)Popping Elements (pop()): my_list.pop(index) removes and returns the element at the specified
index. If no index, removes the last element.
6)Index of Element (index()):my_list.index(element) returns the index of the first occurrence of
the specified element in the list.
7)Count Occurrences (count()): my_list.count(element) returns the number of occurrences of the
specified element in the list.
8)Sorting (sort()): my_list.sort() sorts the elements of the list in ascending order. Use
reverse=True for descending order.
9)Reversing Elements (reverse()): my_list.reverse() reverses the order of elements in the list.
10)Concatenation (+): new_list = list1 + list2 concatenates two lists or tuples.
11)Repetition (*): new_list = my_list * 3 repeats the elements of the list or tuple three times.