What will be the output?
a = [1, 2, 3]b = ab.append(4)print(a)
[1, 2, 3]
[1, 2, 3, 4]
[4]
Error
What will be the output of the following Python code?
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]]
[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]
Returns None
Throws a KeyError
Creates a new key with a default value
Crashes the program
What is the output of following code
x = [10, 20, 30]print(x * 0)
[0, 0, 0]
[ ]
0
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]
print(list1[0])
print(list1[:2])
print(list1[:-2])
all of the mentioned
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
[2, 6, 4]
[1, 3, 2, 1, 3]
[1, 3, 2, 1, 3, 2]
[1, 3, 2, 3, 2, 1]
list1.sum(5)
list1.add(5)
listl.append(5)
list1.addelement(5)
myList = [1, 2, 3, 4, 5, 6]for i in range(1, 6): myList[i - 1] = myList[i] for i in range(0, 6): print(myList[i], end = " ")
2 3 4 5 6 1
6 1 2 3 4 5
2 3 4 5 6 6
1 1 2 3 4 5
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
What is the output when we execute
list("hello") ?
['h', 'e', 'l', 'l', 'o']
[' hello']
['llo']
['olleh']
a=[1,2,3]a[::-1]print(a)
[1,2,3]
[3,2,1]
[2,1,3]
[3,1,2]
Tuple
Integer
String
List
list1=[1,3]list2=list1list1[0]=4print(list2)
[1, 4]
[1,3, 4]
[4,3]
[1,3]
a = [1, 2, 3]a.insert(1, 10)print(a)
[1, 10, 2, 3]
[10, 1, 2, 3]
[1, 2, 10, 3]
a=[2,3,4,5]a.insert(3,1)print(a)
[3,2,3,4,5]
[2, 3, 4, 1, 5]
[2, 3,1, 4, 5]
[2, 3,3, 4, 5]
Appending
Concatenation
Deleting
Slicing
a = "Python"print(a[-4:-1])
tho
yth
hon
thoN
list1 = list()
list1 = []
list1 = list([1, 2, 3])
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 snippet?
for i in [1, 2, 3, 4][::-1]: print (i)
1 2 3 4
4 3 2 1
error
none of the mentioned
It returns None.
It raises an IndexError
It creates a new element at that index.
It returns an empty list.
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]))
1
2
4
5
a = [5,2,3]print(a[5:])
None
What is the output of the following code?
list1=[2, 33, 222, 14, 25]print(list1[ : -1 ])
[2, 33, 222, 14]
25
[25, 14, 222, 33, 2]
What will be the output of the following ?
print((range(4)))
0,1,2,3
[0,1,2,3]
range(0, 4)
(0,1,2,3)
list1.remove("hello")
list1.remove(hello)
list1.removeAll("hello")
list1.removeOne ("hello")
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
{}
[]
<>
()
myList = [1, 5, 5, 5, 5, 1]max = myList[0]indexOfMax = 0for i in range(1, len(myList)): if myList[i] > max: max = myList[i] indexOfMax = i print(indexOfMax)
3
s[]
s.getitem(3)
s.__getitem__(3)
s.getItem(3)
[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]
a = [1, 2, 3]print(a + [4, 5])
[1, 2, 3, 4, 5]
[5, 7, 8]
[4, 5, 1, 2, 3]
[3, 4, 5, 20, 5, 25, 1, 3, 34, 5]
[1, 3, 3, 4, 5, 5, 20, 25, 34, 5]
[25, 20, 5, 5, 4, 3, 3, 1, 34, 5]
[1, 3, 4, 5, 20, 5, 25, 3, 34, 5]
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 = " ")
4 5 6 7
1 3 8 12
2 5 9 13
What data type is the object below ?
L=[1, 23, 'hello', 1]
Dictionary
Array
[3, 4, 5, 20, 5, 25, 1]
list1 = [1, 3]list2 = list1list1[0] = 4print(list2)
[1, 3]
[4, 3]
[1, 3, 4]
copy = list(original)
copy = original[:]
copy = original.copy()
All of the above
x = ['ab', 'cd']for i in x: i.upper() print(x)
[‘ab’, ‘cd’]
[‘AB’, ‘CD’]
[None, None]
[25, 20, 5, 5, 4, 3, 3, 1]
[3, 1, 25, 5, 20, 5, 4, 3]
list1.append(5)
list1.addLast(5)
list1.addEnd(5)
['hello']
['h', 'e', l', 'l', 'o']
None of the above
mylist=list("a#b#c#d".split('#'))print(mylist)
[‘a’, ‘b’, ‘c’, ‘d’]
[‘a b c d’]
[‘a#b#c#d’]
[‘abcd’]
places = ['Bangalore', 'Mumbai', 'Delhi'] places1 = places places2 = places[:] places1[1]="Pune" places2[2]="Hyderabad" print(places)
[‘Bangalore’, ‘Pune’, ‘Hyderabad’]
[‘Bangalore’, ‘Pune’, ‘Delhi’]
[‘Bangalore’, ‘Mumbai’, ‘Delhi’]
[‘Bangalore’, ‘Mumbai’, ‘Hyderabad’]