Question 1
Find the output of the following program:
nameList = ['Harsh', 'Pratik', 'Bob', 'Dhruv']
pos = nameList.index("GeeksforGeeks")
print (pos * 3)
GeeksforGeeks GeeksforGeeks GeeksforGeeks
Harsh
Harsh Harsh Harsh
ValueError: \'GeeksforGeeks\' is not in list
Question 2
Find the output of the following program:
li = ['a', 'b', 'c', 'd', 'e']
print(li[10:] )
[\'a\', \'b\', \'c\', \'d\', \'e\']
[ \'c\', \'d\', \'e\']
[ ]
[\'a\', \'b\']
Question 3
Find the output of the following program:
def REVERSE(a):
a.reverse()
return(a)
def YKNJS(a):
b = []
b.extend(REVERSE(a))
print(b)
a = [1, 3.1, 5.31, 7.531]
YKNJS(a)
[1, 3.1, 5.31, 7.531]
[7.531, 5.31, 3.1, 1]
IndexError
AttributeError: ‘NoneType’ object has no attribute ‘REVERSE’
Question 4
Find the output of the following program:
li = [1, 3, 5, 7, 9]
print(li.pop(-3), end = ' ')
5
9
7
3
Question 5
Find the output of the following program:
a = [1, 2, 3, 4]
b = a
c = a.copy()
d = a
a[0] = [5]
print(a, b, c, d)
[5, 2, 3, 4] [5, 2, 3, 4] [1, 2, 3, 4] [1, 2, 3, 4]
[[5], 2, 3, 4] [[5], 2, 3, 4] [[5], 2, 3, 4] [1, 2, 3, 4]
[5, 2, 3, 4] [5, 2, 3, 4] [5, 2, 3, 4] [1, 2, 3, 4]
[[5], 2, 3, 4] [[5], 2, 3, 4] [1, 2, 3, 4] [[5], 2, 3, 4]
Question 6
Find the output of the following program:
li = [1, 1.33, 'GFG', 0, 'NO', None, 'G', True]
val1, val2 = 0,''
for x in li:
if(type(x) == int or type(x) == float):
val1 += x
elif(type(x) == str):
val2 += x
else:
break
print(val1, val2)
2 GFGNO
2.33 GFGNOG
2.33 GFGNONoneGTrue
2.33 GFGNO
Question 7
Find the output of the following program:
a = []
a.append([1, [2, 3], 4])
a.extend([7, 8, 9])
print(a[0][1][1] + a[2])
Type Error
12
11
38
Question 8
Find the output of the following program:
a = [x for x in (x for x in 'Geeks 22966 for Geeks' if x.isdigit()) if
(x in ([x for x in range(20)]))]
print(a)
[2, 2, 9, 6, 6]
[ ]
Compilation error
Runtime error
Question 9
Find the output of the following program:
a = 'Geeks 22536 for 445 Geeks'
b = [x for x in (int(x) for x in a if x.isdigit()) if x%2 == 0]
print(b)
[2, 2, 6, 4, 4]
Compilation error
Runtime error
[‘2’, ‘2’, ‘5’, ‘3’, ‘6’, ‘4’, ‘4’, ‘5’]
Question 10
Find the output of the following program:
a = ['Geeks', 'for', 'Geeks']
b = [i[0].upper() for i in a]
print(b)
[‘G’, ‘F’, ‘G’]
[‘GEEKS’, ‘FOR’, ‘GEEKS’]
[‘GEEKS’]
Compilation error
There are 25 questions to complete.