List is mutable & Tuple is immutable
List is immutable & Tuple is mutable
Both List and Tuple are Mutable
Both List and Tuple are Immutable
0
4
1
2
[‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
[‘hello’]
[‘llo’]
[‘olleh’]
What is the correct command to shuffle the following list?
fruit=['apple', 'banana', 'papaya', 'cherry']
fruit.shuffle()
shuffle(fruit)
random.shuffle(fruit)
random.shuffleList(fruit)
What will be the output of the following Python code?
list1 = [1, 3]list2 = list1list1[0] = 4print(list2)
[1, 3]
[4, 3]
[1, 4]
[1, 3, 4]
s[]
s.getitem(3)
s.__getitem__(3)
s.getItem(3)
arr[-2]
arr[2]
arr[-1]
arr[1]
Heeeo
Heelo
Heleo
None
a=["Apple","Ball","Cobra"]a.sort(key=len)print(a)
[‘Apple’, ‘Ball’, ‘Cobra’]
[‘Ball’, ‘Apple’, ‘Cobra’]
[‘Cobra’, ‘Apple’, ‘Ball’]
Invalid syntax for sort()
list1.add(5)
list1.append(5)
list1.addLast(5)
list1.addEnd(5)
values = [[3, 4, 5, 1], [33, 6, 1, 2]]v = values[0][0]for lst in values: for element in lst: if v > element: v = elementprint(v)
3
5
6
matrix = [[1, 2, 3, 4], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]] for i in range(0, 4): print(matrix[i][1], end = " ")
1 2 3 4
4 5 6 7
1 3 8 12
2 5 9 13
def m(list): v = list[0] for e in list: if v < e: v = e return v values = [[3, 4, 5, 1], [33, 6, 1, 2]] for row in values: print(m(row), end = " ")
3 33
1 1
5 6
5 33
25
2445
133
12454
123
s.__len__()
len(s)
size(s)
s.size()
list1.addEnd (5)
list1.addLast (5)
list1.append (5)
What is the output of the following code?
list1=[2, 33, 222, 14, 25]print(list1[ : -1 ])
[2, 33, 222, 14]
Error
[25, 14, 222, 33, 2]
mylist=list("a#b#c#d".split('#'))print(mylist)
[‘a’, ‘b’, ‘c’, ‘d’]
[‘a b c d’]
[‘a#b#c#d’]
[‘abcd’]
9
15
It returns None.
It raises an IndexError
It creates a new element at that index.
It returns an empty list.
list1 = list()
list1 = []
list1 = list([1, 2, 3])
all of the mentioned
['llo']
['hello']
['h', 'e', l', 'l', 'o']
None of the above
word1="Apple" word2="Apple" list1=[1,2,3] list2=[1,2,3] print(word1 is word2) print(list1 is list2)
True True
False True
False False
True False
values = [[3, 4, 5, 1], [33, 6, 1, 2]]v = values[0][0]for row in range(0, len(values)): for column in range(0, len(values[row])): if v < values[row][column]: v = values[row][column]print(v)
33
data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]def ttt(m): v = m[0][0] for row in m: for element in row: if v < element: v = element return vprint(ttt(data[0]))
[2, 6, 4]
[1, 3, 2, 1, 3]
[1, 3, 2, 1, 3, 2]
[1, 3, 2, 3, 2, 1]
What is the output when we execute
list("hello") ?
['h', 'e', 'l', 'l', 'o']
[' hello']
['olleh']
list1=[1,3]list2=list1list1[0]=4print(list2)
[1,3, 4]
[4,3]
[1,3]
[0, 1, 2, 3]
[0, 1, 2, 3, 4]
[0.0, 0.5, 1.0, 1.5]
[0.0, 0.5, 1.0, 1.5, 2.0]
points = [[1, 2], [3, 1.5], [0.5, 0.5]]points.sort()print(points)
[[1, 2], [3, 1.5], [0.5, 0.5]]
[[3, 1.5], [1, 2], [0.5, 0.5]]
[[0.5, 0.5], [1, 2], [3, 1.5]]
[[0.5, 0.5], [3, 1.5], [1, 2]]
what is the output of the following code?
M=['b' *x for x in range(4)] print(M)
['', 'b', 'bb', 'bbb']
['b,'bb', "bbb', "bbbb']
['b','bb', bbb']
none of these
What data type is the object below ?
L=[1, 23, 'hello', 1]
List
Dictionary
Tuple
Array
list1.remove("hello")
list1.remove(hello)
list1.removeAll("hello")
list1.removeOne ("hello")
a=[1,2,3] b=a.append(4) print(a) print(b)
[1,2,3,4] [1,2,3,4]
[1, 2, 3, 4] None
Syntax error
[1,2,3] [1,2,3,4]
def f(values): values[0] = 44 v = [1, 2, 3]f(v)print(v)
[1, 44]
[1, 2, 3, 44]
[44, 2, 3]
[1, 2, 3]
values = [[3, 4, 5, 1 ], [33, 6, 1, 2]]for row in values: row.sort() for element in row: print(element, end = " ") print()
The program prints two rows 3 4 5 1 followed by 33 6 1 2
The program prints on row 3 4 5 1 33 6 1 2
The program prints two rows 1 3 4 5 followed by 1 2 6 33
Returns None
Throws a KeyError
Creates a new key with a default value
Crashes the program
list1.remove(“hello”)
list1.removeAll(“hello”)
list1.removeOne(“hello”)
a=[13,56,17] a.append([87]) a.extend([45,67]) print(a)
[13, 56, 17, [87], 45, 67]
[13, 56, 17, 87, 45, 67]
[13, 56, 17, 87,[ 45, 67]]
[13, 56, 17, [87], [45, 67]]
a= [1, 2, 3, 4, 5]for i in range(1, 5): a[i-1] = a[i]for i in range(0, 5): print(a[i],end = " ")
5 5 1 2 3
5 1 2 3 4
2 3 4 5 1
2 3 4 5 5
[3, 4, 5, 20, 5, 25, 1, 3]
[1, 3, 3, 4, 5, 5, 20, 25]
[3, 5, 20, 5, 25, 1, 3]
[1, 3, 4, 5, 20, 5, 25]
copy = list(original)
copy = original[:]
copy = original.copy()
All of the above
What is the output of the following code:
L=['a','b','c','d']print ( "".join(L))
abcd
[‘a’,’b’,’c’,’d’]
What will be the output of the following code snippet?
a=[1,2,3,4,5,6,7,8,9]a[::2]=10,20,30,40,50,60print(a)
ValueError: attempt to assign sequence of size 6 to extended slice of size 5
[10, 2, 20, 4, 30, 6, 40, 8, 50, 60]
[1, 2, 10, 20, 30, 40, 50, 60]
[1, 10, 3, 20, 5, 30, 7, 40, 9, 50, 60]
pop()
delete()
remove_last()
delete_last()