0% found this document useful (0 votes)
82 views4 pages

Chapter-3 MCQs

The document contains a table with questions and answers related to Python lists, tuples, sets and their properties and methods. Some questions ask about the output of code snippets involving lists, tuples and sets. The answers test knowledge of mutable vs immutable properties, indexing, slicing, built-in functions like len(), min(), max() etc.

Uploaded by

rahul ma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views4 pages

Chapter-3 MCQs

The document contains a table with questions and answers related to Python lists, tuples, sets and their properties and methods. Some questions ask about the output of code snippets involving lists, tuples and sets. The answers test knowledge of mutable vs immutable properties, indexing, slicing, built-in functions like len(), min(), max() etc.

Uploaded by

rahul ma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Sr No Question A B C D Ans

1 Lists are Mutable Immutable Both None of these A


2 How t odefine an empt list list[] l=[] l=() list() B
3 2 1 3 0 A
What is the output of list1=[1,2,3] print(list1[1])
4 Does python allow negative indexing? yes no maybe A
The Slice operation is performed on a list
5 " : . ~ B
using
Which python function is used to return
6 len() length() LEN() LENGTH() A
length?
7 list can be deleted using _____ keyword. remove pop del shift C
8 What is the result of cmp(3, 1)? 1 0 TRUE FALSE A
Which of the following is a Python list?
9 [1, 2, 3] (1, 2, 3) {1, 2, 3} {} A
What will be the output of the following Python
code?
10 (1,2) (1,2,4) (2,4) (2,4,3) C
>>>t=[1,2,4,3]
>>>t[1:3]
What will be the output of the following Python
code?
11 (1,2) (1,2,4) (2,4) (2,4,3) C
>>>t=[1,2,4,3]
>>>t[1:-1]
What will be the output of the following Python
code?
12 [2, 3, 9] [1, 2, 4, 3, 8, 9] [1, 4, 8] [1, 2,4, 8] C
>>>t = [1, 2, 4, 3, 8, 9]
>>>[t[i] for i in range(0, len(t), 2)]
What will be the output of the following Python
code?
13 (1, 1, 2, 2) [1, 1, 2, 2] (1, 2, 1, 2) [1, 2, 1, 2] D
l=[1,2]
print 2*l
What will be the output of the following Python
code?
14 l1=[12,2] 1 0 -1 error A
l2=[4,100]
print cmp(l1,l2)
What will be the output of the following Python
code?
15 12 a 12,a 2 B
l1=[12,2,'a']
print max(l1)
What will be the output of the following Python
code?
16 12 a 12,a 2 D
l1=[12,2,'a']
print min(l1)
What will be the output of the following Python
code?
l1=[12,2,'a']
17 [12, 2, 'a', ['xyz']] [12, 2, 'a', 'xyz'] [ ['xyz'],12, 2, 'a'] [ 'xyz',12, 2, 'a'] A
l2=['xyz']
l1.append(l2)
print l1
What will be the output of the following Python
code?
l1=[12,2,'a']
18 xyz hy [xyz,hy] a B
l2=('xyz','hy')
l1.append(l2)
print l1[3][1]
Which method returns the number of times
19 count() Count() COUNT() All A
elements appear in the list?
What is the output of
l1=[1,2,3,4]
20 [1,2,3,4,6] Error None [6,4,3,2,1] B
l1.extend(6)
print l1
What is the output of
l1=[1,2,3,4]
21 l2=[5,6,7,8] [1, 2, 3, 4, 5, 6, 7, 8] [1, 2, 6, 3, 4] [5, 6, 7, 8, 1, 2, 3, 4] error C
l2.extend(l1)
print l2
What is the output of
22 l1=[1,3,3,4,5] 2 1 0 error D
print l1.index(3,3)
By default pop method removes _____
23 first any last middle C
element.
What is the output of
24 l1=[1,2,3,4,5] 1 5 3 2 C
print l1.pop(-3)
What is the output of
l1=[1,2,3,4,5]
25 [1, 2, 4, 5] [1,2,3,4] [1,2,3,5] [1,2,3,4,5] A
l1.remove(3)
print l1
What is the output of
l1=[1,2,4,5]
26 [1, 2, 4, 5] [1,2,4] [1,2,5] error D
l1.remove(3)
print l1
What is the output of
l1=[1,2,4,5]
27 [1, 2, 4, 5] [5,4,2,1] 0 error B
l1.reverse()
print l1
What is the output of
l1=[1,2,4,5]
28 [1, 2, [23, 34], 4, 5] [1, 2, 23, 34, 4, 5] [1,[23,34],2,4,5] [1,23,34,2,4,5] A
l1.insert(2,[23,34])
print l1
Which method removes all the elements from
29 del() delete() clear() exit() C
the list?
30 Tuple is ______ mutable Immutable both noneof these B
31 Which of the following is a Python tuple? [1,2,3[ {1,2,3} (1,2,3) {} C
Suppose t = (1, 2, 4, 3), which of the following
32 print(t[3]) t[3] = 45 print(max(t)) print(len(t)) B
is incorrect?
What will be the output of the following Python
code?
33 (1,2) (1,2,4) (2,4) (2,4,3) C
>>>t=(1,2,4,3)
>>>t[1:3]
What will be the output of the following Python
code?
34 1 2 5 error D
>>>my_tuple = (1, 2, 3, 4)
>>>my_tuple.append( (5, 6, 7) )
>>>print len(my_tuple)
What will be the output of below Python
code?

tuple1=(5,1,7,6,2)
35 (5,1,6,2) (5,1,7,6) (5,1,7,6,2) Error D
tuple1.pop(2)

print(tuple1)

Which of the following options will not result in


36 an error when performed on tuples in Python tupl[1]=2 tupl.append(2) tupl1=tupl+tupl tupl.sort() C
where tupl=(5,2,7,0,3)?
what will be the output?
tupl=()
37 0 2 1 Error A
tupl1=tupl*2

print(len(tupl1))
Which one of the following is correct syntax to
38 t=(10) t={10} t=10 t=(10,) D
create tuple with one element?
Which of the following is not the correct
39 s={} s=set({}) s=set((1,2,3,4)) B
syntax for creating a set? s={1,2,3,4}
What will be the output of the following Python
code?
40 7 4 8 error B
nums = set([1,1,2,3,3,3,4,4])
print(len(nums))
Which of the following statements is used to
41 {} set( ) [] () B
create an empty set?
If a={5,6,7,8}, which of the following
42 print(len(a)) print(min(a)) a.remove(5) a[2]=45 D
statements is false?
Error as there is no add Error as 5 already exists
43 If a={5,6,7}, what happens when a.add(5) is a={5,5,6,7} a={5,6,7} B
function for set data type in the set
executed?
Is the following Python code valid?
Error, elements of a Error, subsets aren’t
44 Yes, 7 is printed Yes, {7,5} is printed C
a={3,4,{7,5}} set can’t be printed allowed
print(a[2][0])
To add one element in set _____ method is
45 add() append() extend() insert() A
used.
To add more than one item in set _____
46 add() update() extend() insert() B
method is used.
The isdisjoint() method returns True if none of
47 the items are present in both sets, otherwise, TRUE FALSE A
it returns False.
What is the output of the following code
{‘PYnative’, 1, (‘abc’, {‘PYnative’, 1, (‘abc’,
48 Error B
aSet = {1, 'PYnative', ('abc', 'xyz'), True} ‘xyz’), True} ‘xyz’)}
print(aSet)
What is the output of the following

set1 = {10, 20, 30, 40, 50}


False True False True
49 set2 = {60, 70, 10, 30, 40, 80, 20, 50} B
False True True False
print(set1.issubset(set2))
print(set2.issuperset(set1))
What is the output of the following set
operation
{‘Yellow’, ‘Orange’, {‘Yellow’, ‘Orange’,
50 ‘Red’, ‘Black’, ‘Green’, ‘Black’, [“Blue”, Error A
sampleSet = {"Yellow", "Orange", "Black"}
‘Blue’} “Green”, “Red”]}
sampleSet.update(["Blue", "Green", "Red"])
print(sampleSet)
What is the output of the following
{‘Yellow’, ‘Orange’,
51 sampleSet = {"Yellow", "Orange", "Black"} KeyError: ‘Blue’ A
‘Black’}
sampleSet.discard("Blue")
print(sampleSet)

The symmetric_difference() method returns a


52 TRUE FALSE A
set that contains all items from both sets, but
not the items that are present in both sets.
What is the output of the following union
operation

set1 = {10, 20, 30, 40} {40, ’10’, 50, 20, 60, {40, 10, ’10’, 50, 20, 60,
53 {40, 10, 50, 20, 60, 30} ERROR C
set2 = {50, 20, "10", 60} 30} 30}

set3 = set1.union(set2)
print(set3)
What is the output of the following set
operation.

set1 = {"Yellow", "Orange", "Black"} {‘Yellow’, ‘Orange’, {"Yellow", "Orange",


54 {‘Black’, ‘Yellow’} ERROR A
set2 = {"Orange", "Blue", "Pink"} ‘Black’, ‘Blue’, ‘Pink’} "Black"}

set1.difference_update(set2)
print(set1)

55 The union() method returns a new set with all TRUE FALSE A
items from both sets by removing duplicates
What is the output of the following
{‘Blue’, ‘Orange’,
sampleSet = {"Yellow", "Orange", "Black"} {‘Blue’, ‘Orange’,
56 ‘Yellow’, ‘Orange’, ERROR B
sampleSet.add("Blue") ‘Yellow’, ‘Black’}
‘Black’}
sampleSet.add("Orange")
print(sampleSet)
What is the output of the following set
operation

set1 = {"Yellow", "Orange", "Black"} {‘Yellow’, ”Black’, ‘Pink’, {‘Pink’, ‘Blue’}


57 {‘Yellow’, ”Black’} ERROR B
set2 = {"Orange", "Blue", "Pink"} ‘Blue’}

set3 = set2.difference(set1)
print(set3)
What is the output of the following code
58 Yellow Orange ERROR C
sampleSet = {"Yellow", "Orange", "Black"}
print(sampleSet[1])
Which of the following statements create a d = {“john”:40, d = {40:”john”,
59 All D
dictionary? d = {} “peter”:45} 45:”peter”}
Suppose d = {“john”:40, “peter”:45}, to delete
60 the entry for “john” what command do we d.delete(“john”:40) d.delete(“john”) del d[“john”] del d(“john”:40) C
use?
Suppose d = {“john”:40, “peter”:45}. To obtain
61 the number of entries in dictionary which d.size() len(d) size(d) d.len() B
command do we use?
What will be the output of the following Python
code ?
62 [“john”, “peter”] [“john”:40, “peter”:45] (“john”, “peter”) (“john”:40, “peter”:45) A
d = {"john":40, "peter":45}
print(list(d.keys()))
The keys of a
The values of a
dictionary can be Dictionaries aren’t
63 dictionary can be Dictionaries are mutable B
accessed using ordered
accessed using keys
Which of these about a dictionary is false? values
What will be the output of the following Python
code snippet?
64 1A2B3C 12 3 ABC 1:”A” 2:”B” 3:”C” A
a={1:"A",2:"B",3:"C"}
for i,j in a.items():
print(i,j,end=" ")
What will be the output of the following Python
code snippet?
65 1 A 4 ERROR B
a={1:"A",2:"B",3:"C"}
print(a.get(1,4))
What will be the output of above Python
code?
66 abc 5 {"abc":5} ERROR D
d1={"abc":5,"def":6,"ghi":7}

print(d1[0])

You might also like