Python Tuples, Lists and Dictionary MCQ CS 12
Python Tuples, Lists and Dictionary MCQ CS 12
26.Which of the following statement will create an 35.Write the output of the following:
empty tuple? t1 = ('1', '2', '3', '4', '5')
a. P = ( ) b. Q = tuple( ) print(t1 + tuple("tuple"))
c. Both of the above d. None of the above a. (‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘t’, ‘u’, ‘p’, ‘l’, ‘e’)
b. (‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘tuple’)
c. Error d. None of the above
36.Which function returns the length of tuple? 46. Write the output of :
a. length( ) b. len( ) tuple(“ComputerScience”).count(“i”)
c. size( ) d. None of the above a. 1 b. 2
c. 3 d. Error
37.Write the output of the following :
t1 = (1,2)
47.Write the output of : sorted(tuple(“Amit”))
t2 = (2,1)
a. [‘t’, ‘i’, ‘m’, ‘A’] b. [‘A’, ‘m’, ‘i’, ‘t’]
t1 == t2
c. [‘A’, ‘i’, ‘m’, ‘t’] d. None of the above
a. True b. False
c. Error d. None of the above
48.Which of the following statement create tuple?
38.Write the output of the following : a. t1 = (1, 2, 3, 4) b. t1[1] = (1, 2, 3, 4)
t1 = (1,2) c. Both of the above d. None of the above
t2 = (1.0, 2.0)
t1 == t2 49.Which of the following operation work on tuples?
a. True b. False a. Concatenation b. Slicing
c. Error d. None of the above c. Repetition d. All of the above
39.del t1 statement will delete the tuple named 50.Write the output of the following:
‘t1’.(T/F) (n1,n2)=tuple("25")
a. True b. False n2+n1
a. 7 b. 25
40.What type of error is shown by following c. 52 d. Error
statement?
t1 =(1, 2) 51.What is the length of given tuple?
t2 ((((1,2,3,4),‘a’,‘b’),’g’,1,3),“Sonu”)
a. ValueError b. TypeError a. 4 b. 3
c. NameError d. None of the above c. 2 d. 1
41. Write the output of the following. 52.Write the output of the following:
t1=((1,2),(3,4),(9,)) t1= ((101,"Amit",98), (102,"Geetu",95),
max(t1) (103,"Manoj",87),(104,"Sawan",79))
a. 9 b. (9,) str(st[2][2]) + str(st[3][2])
c. (3,4) d. Error a. 193 b. 9587
c. 8779 d. 166
42.min(t1) will return an error if the tuple t1 contains
value of mixed data type.(T/F) 53.Which function takes tuple as argument?
a. True b. False a. max( ) b. min( )
43.Which of the following function return the frequency c. sum( ) d. All of the above
of particular element in tuple?
a. index( ) b. max( ) 54.Write the output of the following:
c. count( ) d. None of the above a=(“Amit”, “Sumit”,”Ashish”,”Sumanta”)
print(max(a))
44. Write the output of the following : a. Sumanta b. Ashish
t1=(1,2,3,4,5,6,7) c. Sumit d. Amit
t1[t1[1]]
a. 2 b. 1 55.What type of error is returned by following code :
c. 3 d. 4 a=(“Amit”, “Sumit”,”Ashish”,”Sumanta”)
print(a.index(“Suman”))
45.Write the output of the following :
a. SyntaxError b. ValueError
t1=(1,2,3,4,5,6,7)
c. TypeError d. NameError
t1[t1[1]] + t1[t1[-4]]
a. 8 b. 9
c. 6 d. 7
56.Write the output of the following : 61.Write the output of the following :
a=(“Amit”, “Sumit”,”Ashish”,”Sumanta”) a=("Hello","How","are","you")
print(a.index(“Sumit”)+4//3**2) for i in a:
a. 2 b. 4 print(i,end=" ")
c. 1 d. 3 a. “Hello” , “How” , “are” , “you”
b. Hello , How , are , you
57.Write the output of the following: c. Hello How are you
a=(“Amit”,“Sumit”,”Ashish”,”Sumanta”) d. Error
print(a.count(“Sum”))
a. 1 b. 2 62.Write the output of the following:
c. 0 d. Error a=("Hello","How","are","you")
for i in a:
58.Write the output of the following : print(a.index(i),end=" ")
a=("Amit", "Sumit","Ashish","Sumanta") a. 0 1 2 3 b. “Hello” , “How” , “are” , “you”
for i in a: c. Error d. 0 2 3
print(len(i)**2)
a. b. 63.Write the output of the following:
0 16 a=(“Hello”,”How”,”are”,”you”)
1 25 b=list(a)
4 36 print(a==b)
9 49 a. SyntaxError b. ValueError
c. True d. False
c. d.
Error 1 64.Write the output of the following:
4 a=("Amita", "How", "are", "you", "a")
9 for i in range(len(a)):
16 if(a[i]=="a"):
print(a[i])
59.Write the output of the following: a. Hello b. How
a=(6,8,9,"Sumanta",1) c. a d. you
for i in a:
print(str(i)*2) 65.To which of the following the “in” operator can be
a. b. used to check if an item is in it?
66 66 a.Lists b.Dictionary
88 88 c.Tuples d.All of the above
99 99
SumantaSumanta Error 66. Which of the following is a Python tuple?
11 a. [1, 2, 3] b.(1,2,3)
c d. c.{1, 2, 3} d.{}
Error 66
88 67.Suppose t = (1, 2, 4, 3), which of the following is
99 incorrect?
SumantaSumanta a. print(t[3]) b.T[3] = 45
Error c.print(max(t)) d.print(len(t))
60. Write the output of the following: 68. What will be the output of the following Python
a="blog" code?
b=list(a) t=(1,2,4,3)
c=tuple(b) t[1:3]
print(c) a. (1, 2) b.(1, 2, 4)
a. Error b. [‘b’ , ‘l’ , ‘o’ , ‘g’] c. (2,4) d.(2, 4, 3)
c. (‘b’ , ‘l’ , ‘o’ , ‘g’) d. (blog)
69. What will be the output of the following Python 5.Suppose list1 is [3, 5, 25, 1, 3], what is
code? min(list1)?
t=(1,2,4,3) a) 3 b) 5
t[1:-1] c) 25 d) 1
a. (1, 2) b.(1, 2, 4)
c. (2,4) d.(2, 4, 3) 6.Suppose list1 is [1, 5, 9], what is sum(list1)?
a) 1 b) 9
70.What will be the output of the following Python c) 15 d) Error
code?
t = (1, 2, 4, 3, 8, 9)
7.To shuffle the list(say list1) what function do we
[t[i] for i in range(0, len(t), 2)]
use?
a. [2, 3, 9] b. [1, 2, 4, 3, 8, 9]
a) list1.shuffle() b) shuffle(list1)
c. [1, 4, 8] d.(1, 4, 8)
c) random.shuffle(list1) d) random.shuffleList(list1)
71.What will be the output of the following Python
code? 8.Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], Which of the
t = (1, 2) following is correct syntax for slicing operation?
2 * t a) print(list1[0]) b) print(list1[:2])
a.(1, 2, 1, 2) b. [1, 2, 1, 2] c) print(list1[:-2]) d) all of the mentioned
c.(1, 1, 2, 2) d.[1, 1, 2, 2]
9.Suppose list1 is [2,33,222,14,25], What is list1[:-1]?
72. What will be the output of the following Python a) [2, 33, 222, 14] b) Error
code? c) 25 d) [25, 14, 222, 33, 2]
t1 = (1, 2, 4, 3)
t2 = (1, 2, 3, 4) 10.What will be the output of the following Python
t1 < t2 code?
a.True b.False names=['Amir','Bear','Charlton','Daman']
c.Error d.None print(names[-1][-1])
a) A b) Daman
LISTS MCQ c) Error d) n
11.What will be the output of the following Python
1.Which of the following commands will create a list? code?
a) list1 = list() b) list1 = [ ] names1=['Amir','Bear','Charlton','Daman']
names2 = names1
c) list1 = list([1, 2, 3]) d) all of above
names3 = names1[:]
names2[0] = 'Alice'
2.What is the output when we execute names3[1] = 'Bob'
list(“hello”)? sum = 0
a) [‘h’, ‘e’, ‘l’, ‘l’, ‘o’] b) [‘hello’] for ls in(names1, names2, names3):
c) [‘llo’] d) [‘olleh’] if ls[0] == 'Alice':
sum += 1
3.Suppose list L is [‘h’,’e’,’l’,’l’,’o’], what is
if ls[1] == 'Bob':
len(L)?
sum += 10
a) 5 b) 4 print sum
c) None d) Error a) 11 b) 12
c) 21 d) 22
4.Suppose list1 is [2445,133,12454,123], what is
max(list1)? 12.Suppose list1 is [1, 3, 2], What is list1*2?
a) 2445 b) 133 a) [2, 6, 4] b) [1, 3, 2, 1, 3]
c) 12454 d) 123 c) [1, 3, 2, 1, 3, 2] d) [1, 3, 2, 3, 2, 1]
13.Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is: 22.Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3],
a) [0, 1, 2, 3] b) [0, 1, 2, 3, 4] what is list1 after listExample.pop(1)?
c) [0.0, 0.5, 1.0, 1.5] d) [0.0, 0.5, 1.0, 1.5, 2.0] a) [3, 4, 5, 20, 5, 25, 1, 3]
b) [1, 3, 3, 4, 5, 5, 20, 25]
14.What will be the output of the following Python c) [3, 5, 20, 5, 25, 1, 3]
code? d) [1, 3, 4, 5, 20, 5, 25]
list1 = [11, 2, 23]
list2 = [11, 2, 2] 23.Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3],
list1 < list2 what is list1 after listExample.pop()?
a) True b) False a) [3, 4, 5, 20, 5, 25, 1]
c) Error d) None b) [1, 3, 3, 4, 5, 5, 20, 25]
c) [3, 5, 20, 5, 25, 1, 3]
15.To add a new element to a list we use which d) [1, 3, 4, 5, 20, 5, 25]
command?
a) list1.add(5) b) list1.append(5)
24.What will be the output of the following Python
c) list1.addLast(5) d) list1.addEnd(5)
code?
"Welcome to Python".split()
16.To insert 5 to the third position in list1, we use
a) [“Welcome”, “to”, “Python”]
which command?
b) (“Welcome”, “to”, “Python”)
a) list1.insert(3, 5) b) list1.insert(2, 5)
c) {“Welcome”, “to”, “Python”}
c) list1.add(3, 5) d) list1.append(3, 5)
d) “Welcome”, “to”, “Python”
17.To remove string “hello” from list1, we use which 25.What will be the output of the following Python
command? code?
a) list1.remove(“hello”) b) list1.remove(hello) list("a#b#c#d".split('#'))
c) list1.removeAll(“hello”) d) list1.removeOne(“hello”) a) [‘a’, ‘b’, ‘c’, ‘d’]
b) [‘a b c d’]
18.Suppose list1 is [3, 4, 5, 20, 5], what is c) [‘a#b#c#d’]
list1.index(5)? d) [‘abcd’]
a) 0 b) 1
c) 4 d) 2 26.What will be the output of the following Python
code?
19.Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is myList = [1, 2, 3, 4, 5, 6]
list1.count(5)? for i in range(1, 6):
a) 0 b) 4 myList[i - 1] = myList[i]
c) 1 d) 2 for i in range(0, 6):
print(myList[i], end = " ")
20.Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is a) 2 3 4 5 6 1
list1 after list1.reverse()? b) 6 1 2 3 4 5
a) [3, 4, 5, 20, 5, 25, 1, 3] c) 2 3 4 5 6 6
b) [1, 3, 3, 4, 5, 5, 20, 25] d) 1 1 2 3 4 5
c) [25, 20, 5, 5, 4, 3, 3, 1]
d) [3, 1, 25, 5, 20, 5, 4, 3] 27.What will be the output of the following Python
code?
21.Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], list1 = [1, 3]
what is list1 after list2 = list1
listExample.extend([34, 5])? list1[0] = 4
a) [3, 4, 5, 20, 5, 25, 1, 3, 34, 5] print(list2)
b) [1, 3, 3, 4, 5, 5, 20, 25, 34, 5] a) [1, 3] b) [4, 3]
c) [25, 20, 5, 5, 4, 3, 3, 1, 34, 5] c) [1, 4] d) [1, 3, 4]
d) [1, 3, 4, 5, 20, 5, 25, 3, 34, 5]
28.What will be the output of the following Python 34.What will be the output of the following Python
code? code?
def f(values): veggies=['carrot','broccoli','potato','asparagus']
values[0] = 44 veggies.insert(veggies.index('broccoli'),'celery')
print(veggies)
v = [1, 2, 3] a)[‘carrot’,‘celery’,‘broccoli’,‘potato’, ‘asparagus’]
f(v) b)[‘carrot’, ‘celery’, ‘potato’, ‘asparagus’]
c)[‘carrot’,‘broccoli’,‘celery’, ‘potato’,‘asparagus’]
print(v)
d)[‘celery’,‘carrot’, ‘broccoli’,‘potato’,‘asparagus’]
a) [1, 44] b) [1, 2, 3, 44]
c) [44, 2, 3] d) [1, 2, 3]
35.What will be the output of the following Python
code?
29.What will be the output of the following Python
data=[[[1,2],[3,4]],[[5,6],[7,8]]]
code?
print(data[1][0][0])
names1 = ['Amir', 'Bala', 'Chales']
if 'amir' in names1: a) 1 b) 2
print(1) c) 4 d) 5
else:
print(2) 36.What will be the output of the following Python code?
a) None b) 1 a=[10,23,56,[78]]
c) 2 d) Error b=list(a)
a[3][0]=95
30.What will be the output of the following Python a[1]=34
code? print(b)
numbers = [1, 2, 3, 4] a) [10,34,56,[95]] b) [10,23,56,[78]]
numbers.append([5,6,7,8]) c) [10,23,56,[95]] d) [10,34,56,[78]]
print(len(numbers))
a) 4 b) 5
c) 8 d) 12
37. What will be the output of the following Python code?
lst=[3,4,6,1,2]
31.To which of the following the “in” operator can be
lst[1:2]=[7,8]
used to check if an item is in it?
print(lst)
a) Lists b) Dictionary
c) Tuple d) All of the mentioned a) [3, 7, 8, 6, 1, 2] b) Syntax error
c) [3,[7,8],6,1,2] d) [3,4,6,7,8]
32.What will be the output of the following Python
code? 38.What will be the output of the following Python code?
list1 = [1, 2, 3, 4] a=[13,56,17]
list2 = [5, 6, 7, 8] a.append([87])
print(len(list1 + list2)) a.extend([45,67])
a) 2 b) 4 print(a)
c) 5 d) 8 a) [13, 56, 17, [87], 45, 67]
b) [13, 56, 17, 87, 45, 67]
33. What will be the output of the following Python c) [13, 56, 17, 87,[ 45, 67]]
code? d) [13, 56, 17, [87], [45, 67]]
def addItem(listParam):
listParam += [1] 39.What is the output of the following piece of code?
mylist = [1, 2, 3, 4] a=list((45,)*4)
addItem(mylist) print((45)*4)
print(len(mylist)) print(a)
a) 1 b) 4 (a) 180
c) 5 d) 8 [(45),(45),(45),(45)]
(b) (45,45,45,45) DICTIONARY MCQ
[45,45,45,45]
(c) 180 1. Which of the following statements create a
[45,45,45,45]
dictionary?
(d) Syntax Error
a. D = {}
b. D = {“john”:40, “peter”:45}
40.What will be the output of the following Python
c. D = {40:”john”, 45:”peter”}
code?
d. All of the mentioned
word1="Apple"
word2="Apple"
2. What will be the output of the following Python
list1=[1,2,3]
code?
list2=[1,2,3]
d = {"john":40, "peter":45}
print(word1 is word2)
d["john"]
print(list1 is list2)
a. 40 b.45
(a) True
c.“john” d.“peter”
True
(b) False
3. What will be the output of the following Python code
True
snippet?
(c) False
d = {"john":40, "peter":45}
False
d.keys()
(d) True
a. “john”, 40, 45, and “peter”
False
b. “john” and “peter”
c.40 and 45
41.What will be the output of the following Python
d. D = (40:”john”, 45:”peter”)
code?
def change(var, lst):
4. What will be the output of the following Python
var = 1
code snippet?
lst[0] = 44
d = {"john":40, "peter":45}
k = 3
"john" in d
a = [1, 2, 3]
a.True b.False
change(k, a)
c.None d. Error
print(k)
print(a)
5. Which of these about a dictionary is false?
a. The values of a dictionary can be accessed
(a) 3 using keys
[44,2,3] b. The keys of a dictionary can be accessed using
(b) 1 values
[1,2,3] c. Dictionaries aren’t ordered
(c) 3 d. Dictionaries are mutable
[1,2,3]
(d) 1 6. Which of the following is not a declaration of the
[44,2,3] dictionary?
a. {1: ‘A’, 2: ‘B’}
b. Dict([[1,”A”],[2,”B”]])
c.{1,”A”,2”B”}
d.{ }
31. What will be the output of the following Python 36. Which of the following is correct with respect to
code snippet? above Python code?
a={} d={"a":3,"b":7}
a['a']=1 a). a dictionary d is created.
a['b']=[2,3,4] b). a and b are the keys of dictionary d.
print(a) c). 3 and 7 are the values of dictionary d
d). All of the above.
a) Exception is thrown b) {‘b’: [2], ‘a’: 1}
c) {‘b’: [2], ‘a’: [3]} d) {‘b’: [2, 3, 4], ‘a’: 1} 37. Which one of the following is correct?
a). In python, a dictionary can have two same keys
32. What will be the output of the following Python with different values.
code? b). In python, a dictionary can have two same values
count={} with different keys
count[(1,2,4)] = 5 c). In python, a dictionary can have two same keys or
count[(4,2,1)] = 7 same values but cannot have two same key-value pair
count[(1,2)] = 6 d). In python, a dictionary can neither have two same
count[(4,2,1)] = 2 keys nor two same values.
tot = 0
for i in count: 38. What will be the output of above Python code?
tot=tot+count[i] d1={"abc":5,"def":6,"ghi":7}
print(len(count)+tot) print(d1[0])
a) 25 b) 17 a). abc b). 5
c) 16 d) Tuples can’t be made keys of a dictionary c). {"abc":5} d). Error
39. What will the above Python code do? 45. What will be the output of above Python code?
dict={"Phy":94,"Che":70,"Bio":82,"Eng":95} C={1:‘R’,2:‘T’,3:‘Y’,40:‘B’,25:‘V’}
dict.update({"Che":72,"Bio":80}) C.update({‘60’:‘NE’})
a) It will create new dictionary as print(C[‘60’])
dict={"Che":72,"Bio":80} and old dict will be (a) NE (b) ‘NE’
deleted. (c) ‘ ‘ (d) Error
b) It will throw an error as dictionary cannot be
updated.
c) It will simply update the dictionary as
dict={"Phy":94,"Che":72,"Bio":80,"Eng":95}
d) It will not throw any error but it will not do any
changes in dict
a) fruits['grapes'] b) fruits['grapes'] = 15
c) insert 'grapes' in fruits d) fruits[15] = 'grapes'
(a) {“Fruit”:[‘Apple’,‘Orange’,‘Banana’,‘Watermelon’]}
(b) {[‘Apple’,‘Orange’,‘Watermelon’]}
(c) {“Fruit”:[‘Apple’,‘Orange’,‘Watermelon’]}
(d) {‘Fruit’}