MCQ
MCQ
MCQ
a) 31 characters
b) 63 characters
c) 79 characters
View Answer
Answer: d
a) X^y
b) X**y
c) X^^y
View Answer
Answer: b
3.What error occurs when you execute the following Python code snippet?
apple = mango
a) SyntaxError
b) NameError
c) ValueError
d) TypeError
View Answer
Answer: b
a) True
b) False
c) Machine dependent
d) Error
View Answer
Answer: b
Explanation: Neither of 0.1, 0.2 and 0.3 can be represented accurately in binary. The round off errors
from 0.1 and 0.2 accumulate and hence there is a difference of 5.5511e-17 between (0.1 + 0.2) and 0.3.
x = int(43.55+2/2)
a) 43
b) 44
c) 22
d) 23
View Answer
Answer: b
Explanation: The expression shown above is an example of explicit conversion. It is evaluated as
int(43.55+1) = int(44.55) = 44. Hence the result of this expression is 44.
a) True
b) False
View Answer
Answer: b
Explanation: The value of the expression (2**2)**3 = 4**3 = 64. When the expression 2**2**3 is
evaluated in python, we get the result as 256, because this expression is evaluated as 2**(2**3). This is
because the associativity of exponentiation operator (**) is from right to left and not from left to right.
7.What will be the output of the following Python code snippet if x=1?
x<<2
a) 8
b) 1
c) 2
d) 4
View Answer
Answer: d
Explanation: The binary form of 1 is 0001. The expression x<<2 implies we are performing bitwise left
shift on x. This shift yields the value: 0100, which is the binary form of the number 4.
4^12
a) 2
b) 4
c) 8
d) 12
View Answer
Answer: c
Explanation: ^ is the XOR operator. The binary form of 4 is 0100 and that of 12 is 1100. Therefore,
0100^1100 is 1000, which is equal to 8.
print("hello")
print("good")
else:
print("bad")
a) error
b) hello
c) good
d) bad
View Answer
Answer: c
Explanation: The code shown above prints the appropriate option depending on the conditions given.
The condition which matches is (9>0), and hence the output is: good.
for i in x:
print(i.upper())
a) a b c d
b) A B C D
c) a B C D
d) error
View Answer
Answer: b
for x, y in d.items():
print(x, y)
a) 0 1 2
b) a b c
c) 0 a 1 b 2 c
View Answer
Answer: c
for i in range(int(2.0)):
print(i)
a) 0.0 1.0
b) 0 1
c) error
View Answer
Answer: b
for i in string:
a) m, y, , n, a, m, e, , i, s, , x,
b) m, y, , n, a, m, e, , i, s, , x
d) error
View Answer
Answer: a
a) +
b) *
c) –
View Answer
Answer: c
a) 2
b) 1
c) None
d) 0
View Answer
Answer: a
print("xyyzxyzxzxyy".count('yy'))
a) 2
b) 0
c) error
Answer: a
Explanation: Counts the number of times the substring ‘yy’ is present in the given string.
print("ccdcddcd".find("c"))
a) 4
b) 0
c) Error
d) True
View Answer
Answer: b
Explanation: The first position in the given string at which the substring can be found is returned.
b) [‘hello’]
c) [‘llo’]
d) [‘olleh’]
View Answer
Answer: a
b) 4
c) None
d) Error
View Answer
Answer: a
a) 2445
b) 133
c) 12454
d) 123
View Answer
Answer: c
a) 1
b) 9
c) 15
d) Error
View Answer
Answer: c
Explanation: Sum returns the sum of all elements in the list.
a) Error
b) None
c) 25
d) 2
View Answer
Answer: c
a) [2, 6, 4]
b) [1, 3, 2, 1, 3]
c) [1, 3, 2, 1, 3, 2]
d) [1, 3, 2, 3, 2, 1]
View Answer
Answer: c
a) list1.add(5)
b) list1.append(5)
c) list1.addLast(5)
d) list1.addEnd(5)
View Answer
Answer: b
25.To which of the following the “in” operator can be used to check if an item is in it?
a) Lists
b) Dictionary
c) Set
View Answer
Answer: d
list1 = [1, 2, 3, 4]
list2 = [5, 6, 7, 8]
print(len(list1 + list2))
a) 2
b) 4
c) 5
d) 8
View Answer
Answer: d
Explanation: + appends all the elements individually into a new list.
points.sort()
print(points)
View Answer
Answer: c
>>> a=[14,52,7]
>>>> b=a.copy()
>>> b is a
a) True
b) False
View Answer
Answer: b
Explanation: List b is just a copy of the original list. Any copy made in list b will not be reflected in list a.
29.Write the list comprehension to pick out only negative integers from a given list ‘l’.
a) [x<0 in l]
b) [x for x<0 in l]
c) [x in l for x<0]
d) [x for x in l if x<0]
View Answer
Answer: d
Explanation: To pick out only the negative numbers from a given list ‘l’, the correct list comprehension
statement would be: [x for x in l if x<0].
30.Write a list comprehension for number and its cube for l=[1, 2, 3, 4, 5, 6, 7, 8, 9].
a) [x**3 for x in l]
b) [x^3 for x in l]
c) [x**3 in l]
d) [x^3 in l]
View Answer
Answer: a
Explanation: The list comprehension to print a list of cube of the numbers for the given list is: [x**3 for x
in l].
a) [1, 2, 3]
b) (1, 2, 3)
c) {1, 2, 3}
d) {}
View Answer
Answer: b
a) print(t[3])
b) t[3] = 45
c) print(max(t))
d) print(len(t))
View Answer
Answer: b
Explanation: Values cannot be modified in the case of tuple, that is, tuple is immutable.
>>>t=(1,2,4,3)
>>>t[1:3]
a) (1, 2)
b) (1, 2, 4)
c) (2, 4)
d) (2, 4, 3)
View Answer
Answer: c
d = {"john":40, "peter":45}
d["john"]
a) 40
b) 45
c) “john”
d) “peter”
View Answer
Answer: a
>>>t1 = (1, 2, 4, 3)
>>>t2 = (1, 2, 3, 4)
>>>t1 < t2
a) True
b) False
c) Error
d) None
View Answer
Answer: b
>>> a=(1,2,(4,5))
>>> b=(1,2,(3,4))
>>> a<b
a) False
b) True
d) Error, < operator is valid for tuples but not if there are sub-tuples
View Answer
Answer: a
Explanation: Since the first element in the sub-tuple of a is larger that the first element in the subtuple
of b, False is printed.
>>> a=(2,3,4)
>>> sum(a,3)
c) 12
d) 9
View Answer
Answer: c
Explanation: In the above case, 3 is the starting value to which the sum of the tuple is added to.
>>> a=(1,2,3,4)
>>> del a
View Answer
Answer: c
a) Array of tuples
b) List of tuples
c) Tuples of lists
d) Invalid type
View Answer
Answer: b
Explanation: The variable a has tuples enclosed in a list making it a list of tuples.
View Answer
Answer: c
Explanation: For unpacking to happen, the number of values of the right hand side must be equal to the
number of variables on the left hand side.
>>> a=(1,2)
>>> b=(3,4)
>>> c=a+b
>>> c
a) (4,6)
b) (1,2,3,4)
d) None
View Answer
Answer: b
Explanation: In the above piece of code, the values of the tuples aren’t being changed. Both the tuples
are simply concatenated.
42. What will be the output of the following Python code?
>>> a,b=6,7
>>> a,b=b,a
>>> a,b
a) (6,7)
b) Invalid syntax
c) (7,6)
d) Nothing is printed
View Answer
Answer: c
a) yes
b) no
c) machine dependent
View Answer
Answer: a
a) /
b) //
c) %
View Answer
Answer: b
Explanation: When both of the operands are integer then python chops out the fraction part and gives
you the round off value, to get the accurate answer use floor division. This is floor division. For ex, 5/2 =
2.5 but both of the operands are integer so answer of this expression in python is 2. To get the 2.5
answer, use floor division.
a) 7
b) 1
c) 0
d) 5
View Answer
Answer: b
Explanation: Modulus operator gives the remainder. So, 22%3 gives the remainder, that is, 1.
a) 27
b) 9
c) 3
d) 1
View Answer
Answer: c
Explanation: First this expression will solve 1**3 because exponential has higher precedence than
multiplication, so 1**3 = 1 and 3*1 = 3. Final answer is 3.
>>>str="hello"
>>>str[:2]
>>>
a) he
b) lo
c) olleh
d) hello
View Answer
Answer: a
Explanation: We are printing only the 1st two bytes of string and hence the answer is “he”.
a) list
b) dictionary
c) array
d) tuple
View Answer
Answer: a
Explanation: List data type can store any values within it.
49.In order to store values in terms of key and value we use what core data type.
a) list
b) tuple
c) class
d) dictionary
View Answer
Answer: d
>>>grade1 = 80
>>>grade2 = 90
a) 85.0
b) 85.1
c) 95.0
d) 95.1
View Answer
Answer: a