- Which of the following data types is mutable in Python ?
- int
- str
- list
- tuple
- What is the output of the following code snippet ?
my_list = [1, 2, 3, 4, 5]
result = my_list[1:3]
print(result)
- [1, 2]
- [2, 3]
- [2, 3, 4]
- [1, 3]
- What will be the output of following code ?
x =['XX', 'YY']
for i in x:
i.lower()
print(x)
- ['XX', 'YY']
- ['xx', 'yy']
- [XX, YY]
- None of the above
- How do you add an element to the end of a list ?
- list.append(element)
- list.insert(-1, element)
- list.extend(element)
- list.add(element)
- What is the output of following code ?
a=[[1,2,3],[4,5,6],[7,8,9]]
print(a[1][:])
- [1,2,3]
- [4,5,6]
- [2,5,8]
- None of the above
- What is the data type of following object ?
a= [5,'abc',3.2,6]
- tuple
- array
- list
- dictionary
- What is the result of the following code ?
my_list = [1, 2, 3]
my_list.insert(1, 4)
print(my_list)
- [4, 2, 3]
- [1, 2, 4]
- [1, 4, 2, 3]
- [1, 4, 3]
- How can you remove an element from a list by its value ?
- list.remove(value)
- list.pop(value)
- list.del(value)
- list.exclude(value)
- What does the list.sort() method do ?
- It reverses the order of elements in the list.
- It shuffles the elements randomly within the list.
- It sorts the elements of the list in decending order.
- It sorts the elements of the list in ascending order.
- Assume, q=[3,4,5,20,5,25,1,3], then what will be the items q list after q.pop(1)
- [3,4, 5, 20, 5, 25, 1, 3]
- [1,3,3, 5, 20, 5, 25, 1, 3]
- [3, 5, 20, 5, 25, 1, 3]
- [1, 5, 20, 5, 25, 1, 3]
- How do you find the index of an element in a list ?
- list.get_index(element)
- list.index(element)
- list.locate(element)
- list.find_index(element)
- What is the output of the following code ?
my_list = [1, 2, 3]
new_list = my_list + [4, 5]
print(new_list)
- [1, 2, 3, 4, 5]
- [1, 2, 3, [4, 5]]
- [1, 2, 3, [1, 2, 3, 4, 5]]
- [4, 5, 1, 2, 3]
- How do you reverse the elements of a list ?
- list.reorder()
- list.flip()
- list.sort()
- list.reverse()
- How can you clear all elements from a list ?
- list.clear()
- list.remove_all()
- list.delete_all()
- list.empty()
- How can you create a copy of a list original_list ?
- new_list = original_list.copy()
- new_list = list(original_list)
- new_list = original_list[:]
- All of the above