Python Developer MCQ-Questions
Python Developer MCQ-Questions
7. In python we do not specify types, it is directly interpreted by the compiler, so consider the
following operation to be performed.
1. >>>x = 13 ? 2
objective is to make sure x has a integer value, select all that apply (python 3.xx)
a) x = 13 // 2
b) x = int(13 / 2)
c) x = 13 % 2
d) All of the mentioned
11. The formatting method {1:<10} represents the ___________ positional argument, _________
justified in a 10 character wide field.
a) first, right
b) second, left
c) first, left
d) second, right
1. >>>"a"+"bc"
a) a
b) bc
c) bca
d) abc
18. If a class defines the __str__(self) method, for an object obj for the class, you can use
which command to invoke the __str__ method.
a) obj.__str__()
b) str(obj)
c) print obj
d) all of the mentioned
23. Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], Which of the following is correct syntax for slicing
operation?
a) print(list1[0])
b) print(list1[:2])
c) print(list1[:-2])
d) all of the mentioned
sum = 0
for ls in (names1, names2, names3):
if ls[0] == 'Alice':
sum += 1
if ls[1] == 'Bob':
sum += 10
print sum
a) 11
b) 12
c) 21
d) 22
25. Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.pop()?
a) [3, 4, 5, 20, 5, 25, 1]
b) [1, 3, 3, 4, 5, 5, 20, 25]
c) [3, 5, 20, 5, 25, 1, 3]
d) [1, 3, 4, 5, 20, 5, 25]
26. 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
d) All of the mentioned
27. What will be the output of the following Python code?
1. >>>m = [[x, x + 1, x + 2] for x in range(0, 3)]
a) [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
b) [[0, 1, 2], [1, 2, 3], [2, 3, 4]]
c) [1, 2, 3, 4, 5, 6, 7, 8, 9]
d) [0, 1, 2, 1, 2, 3, 2, 3, 4]
28. What will be the output of the following Python code?
a=[[]]*3
a[1].append(7)
print(a)
a) Syntax error
b) [[7], [7], [7]]
c) [[7], [], []]
d) [[],7, [], []]
29. What will be the output of the following Python code?
a=165
b=sum(list(map(int,str(a))))
print(b)
a) 561
b) 5
c) 12
d) Syntax error
30. What will be the output of the following Python code snippet?
my_string = "hello world"
k = [(i.upper(), len(i)) for i in my_string]
print(k)
a) [(‘HELLO’, 5), (‘WORLD’, 5)]
b) [(‘H’, 1), (‘E’, 1), (‘L’, 1), (‘L’, 1), (‘O’, 1), (‘ ‘, 1), (‘W’, 1), (‘O’, 1), (‘R’, 1), (‘L’, 1), (‘D’, 1)]
c) [(‘HELLO WORLD’, 11)]
d) none of the mentioned
31. 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]
33. Write a list comprehension for producing a list of numbers between 1 and 1000 that are
divisible by 3.
a) [x in range(1, 1000) if x%3==0]
b) [x for x in range(1000) if x%3==0]
c) [x%3 for x in range(1, 1000)]
d) [x%3=0 for x in range(1, 1000)]
34. The service in which the cloud consumer does not manage the underlying cloud
infrastructure nor the application(s) contained in the instances as the service provides user
with all of it is:
A = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
B = [[3, 3, 3],
[4, 4, 4],
[5, 5, 5]]
[B[row][col]*A[row][col] for row in range(3) for col in range(3)]
a) [3, 6, 9, 16, 20, 24, 35, 40, 45]
b) Error
c) [0, 30, 60, 120, 160, 200, 300, 350, 400]
d) 0