Most likely questions for Basic Python
MCQ
1. Who developed Python Programming Language?
a) Wick van Rossum
b) Rasmus Lerdorf
c) Guido van Rossum
d) Niene Stom
2. Which type of Programming does Python support?
a) object-oriented programming
b) structured programming
c) functional programming
d) all of the mentioned
3. Is Python case sensitive when dealing with identifiers?
a) no
b) yes
c) machine dependent
d) none of the mentioned
4. Which of the following is the correct extension of the Python file?
a) .python
b) .pl
c) .py
d) .p
5. What will be the value of the following Python expression?
4+3%5
a) 7
b) 2
c) 4
d) 1
6. Which of the following is used to define a block of code in Python language?
a) Indentation
b) Key
c) Brackets
d) All of the mentioned
7. Which keyword is used for function in Python language?
a) Function
b) def
c) Fun
d) Define
8. What will be the output of the following Python code?
i=1
while True:
if i%3 == 0:
break
print(i)
i+=1
a) 1 2 3
b) error
c) 1 2
d) none of the mentioned
9. Python supports the creation of anonymous functions at runtime, using a construct called
__________
a) pi
b) anonymous
c) lambda
d) none of the mentioned
10. What is the order of precedence in python?
a) Exponential, Parentheses, Multiplication, Division, Addition, Subtraction
b) Exponential, Parentheses, Division, Multiplication, Addition, Subtraction
c) Parentheses, Exponential, Multiplication, Division, Subtraction, Addition
d) Parentheses, Exponential, Multiplication, Division, Addition, Subtraction
11. Which of the following is true for variable names in Python?
a) underscore and ampersand are the only two special characters allowed
b) unlimited length
c) all private members must have leading and trailing underscores
d) none of the mentioned
12. What are the values of the following Python expressions?
2**(3**2)
(2**3)**2
2**3**2
a) 512, 64, 512
b) 512, 512, 512
c) 64, 512, 64
d) 64, 64, 64
13. Which of the following functions is a built-in function in python?
a) factorial()
b) print()
c) seed()
d) sqrt()
14. Which of the following is the use of id() function in python?
a) Every object doesn’t have a unique id
b) Id returns the identity of the object
c) All of the mentioned
d) None of the mentioned
15. What will be the output of the following Python function?
min(max(False,-3,-4), 2,7)
a) -4
b) -3
c) 2
d) False
16. Which of these is the definition for packages in Python?
a) A set of main modules
b) A folder of python modules
c) A number of files containing Python definitions and statements
d) A set of programs making use of Python modules
17. What will be the output of the following Python function?
len(["hello",2, 4, 6])
a) Error
b) 6
c) 4
d) 3
18. What is the output of the following code?
import numpy as np
a = np.arange(10)
print(a[2:5])
a) [2, 3, 4]
b) [0, 1, 2]
c) [5, 6, 7]
d) [2, 4, 6]
19. Which of the following is used to reshape a NumPy array?
a) shape
b) reshape()
c) Both A and B
d) None of the above
20. How many elements will be there in the series named "S1"?
S1 = pd.Series(range(5))
print(S1)
a) 5
b) 4
c) 6
d) None of the above
21. What is the output of the following code?
df = pd.DataFrame(columns = ['tech','fees'])
print(df)
a) Empty DataFrame
b) Empty DataFrame
Columns: []
Index: []
c) Empty DataFrame
Columns: [tech, fees]
Index: []
d) None of the above
22. Which argument keyword can be used to emphasize each point with a specified marker in
plotting?
a) marker_points
b) marker
c) ring
d) types
23. What is the purpose of the pass statement in a function?
a) It is a placeholder for future code
b) It returns a value from the function
c) It prints the result on the screen
d) None of the above
24. What is the purpose of using the ** symbol in function argument unpacking?
a) It allows a tuple of arguments to be passed
b) It allows a list of arguments to be passed
c) It allows a dictionary of arguments to be passed
d) It allows multiple arguments to be passed
25. What will be the output of the following Python code?
min = (lambda x, y: x if x < y else y)
print(min(101*99, 102*98))
a) 9997
b) 9999
c) 9996
d) None of the above
26. What is the output of the following code?
import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c=a+b
print(c)
a) [1, 2, 3, 4, 5, 6]
b) [[1, 4], [2, 5], [3, 6]]
c) [5, 7, 9]
d) Error
27. What is the output of the following code?
arr = np.array([1, 2, 3, 4, 5, 4, 4])
np.where(arr == 4)
a) (array([3.0, 5.0, 6.0], dtype=float64),)
b) (array([3], dtype=int64),)
c) (array([3, 5, 6], dtype=int64),)
d) Error
28. How to select column number 2, 3 and 5 from the dataframe named df?
a) df.iloc[[2,3,5]]
b) df.iloc[2,3,5]
c) df.iloc[[2:5:2]]
d) None of the above
29. We have a dataframe named df having empno, name, salary.
How can we select rows having salary more than 41000 ?
a) df.query("salary >= 41000")
b) df.query("Salary > 41000")
c) df.query("salary > 41000")
d) df.query("salary > 41,000")
30. Which function is used to draw multiple figures in one plot?
a) subplot()
b) subplots()
c) pyplots()
d) subpyplot()
31. Which function is used to draw a scatter plot?
a) scatterplot()
b) pyscatter()
c) scatters()
d) scatter()
32. Why barh() function is used in plotting?
a) To draw a bar graph with a specified height
b) To draw a bar graph to print the highest values of a NumPy array
c) To draw a horizontal bar graph
d) None of the above
33. Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], Which of the following is correct syntax for slicing
operation?
a) print(list1[2:])
b) print(list1[:2])
c) print(list1[:-2])
d) all of the mentioned
34. Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1]?
a) Error
b) None
c) 25
d) 2
35. Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?
a) [2, 33, 222, 14]
b) Error
c) 25
d) [25, 14, 222, 33, 2]
36. What will be the output of the following Python code?
names1 = ['Amir', 'Bear', 'Charlton', 'Daman']
names2 = names1
names3 = names1[:]
names2[0] = 'Alice'
names3[1] = 'Bob'
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
37. Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is:
a) [0, 1, 2, 3]
b) [0, 1, 2, 3, 4]
c) [0.0, 0.5, 1.0, 1.5]
d) [0.0, 0.5, 1.0, 1.5, 2.0]
38. What will be the output of the following Python code?
>>>list1 = [11, 2, 23]
>>>list2 = [11, 2, 2]
>>>list1 < list2
a) True
b) False
c) Error
d) None
39. To add a new element to a list we use which command?
a) list1.add(5)
b) list1.append(5)
c) list1.addLast(5)
d) list1.addEnd(5)
40. To insert 5 to the third position in list1, we use which command?
a) list1.insert(2, 5)
b) list1.insert(3, 5)
c) list1.add(3, 5)
d) list1.append(3, 5)