Jul 1, 2024
[].
marks = [94.4, 87.0, 95.0, 66.0, 45.0]print(marks), print(type(marks)) prints class 'list'.marks[0], marks[1]len() function.
print(len(marks)) prints 5.student = ['Karan', 85, 'Delhi', 92.5]student[0] = 'Arjun'marks.append(50.0) adds 50.0 to the end of the list.marks.sort() sorts the list in ascending order.marks.sort(reverse=True)marks.reverse() reverses the list order.marks.insert(index, value) inserts a value at specified index.marks.remove(value) removes the first occurrence of the value.marks.pop(index) removes element at the specified index.() instead of square brackets.
empty_tuple = (), single_tuple = (1,), multi_tuple = (1, 2, 3)tuple[0], tuple[1:3]tuple.index(value) finds the index of the first occurrence of the value.tuple.count(value) counts occurrences of the value in the tuple.movies = []
movies.append(input('Enter first movie: '))
movies.append(input('Enter second movie: '))
movies.append(input('Enter third movie: '))
print(movies)
def is_palindrome(lst):
reverse_lst = lst.copy()
reverse_lst.reverse()
return lst == reverse_lst
grades = ('A', 'B', 'C', 'A', 'B', 'D', 'A')
print(grades.count('A')) # Outputs: 3
grades_list = list(grades)
grades_list.sort()
print(grades_list) # Outputs: ['A', 'A', 'A', 'B', 'B', 'C', 'D']