Python Programming Multiple Choice Questions
1. Who built the Python programming language?
A) Wick van Rossum
B) Rasmus Lerdorf
C) Guido van Rossum
D) Niene Stom
Answer: C
2. Which of the following is the type of Python?
A) object-oriented programming
B) structured programming
C) functional programming
D) all of the mentioned
Answer: D
3. Keywords in Python are ______?
A) Capitalized
B) lower case
C) UPPER CASE
D) None of the mentioned
Answer: D (Note: Keywords are case-sensitive; some are capitalized like True, False,
None)
4. Which of the following can define a code block in Python programming?
A) Indentation
B) Key
C) Brackets
D) All of the mentioned
Answer: A
5. Which of the following functions will you use to check the Python version?
A) [Link](1)
B) [Link](0)
C) [Link]()
D) [Link]
Answer: D
6. Which of the following is the full form of pip?
A) Pip Installs Python
B) Pip Installs Packages
C) Preferred Installer Program
D) All of the mentioned
Answer: C
7. Which of the following is a built-in function of the Python programming language?
A) factorial()
B) print()
C) seed()
D) sqrt()
Answer: B
8. Which of the following can not be called a core data type of Python?
A) Tuples
B) Lists
C) Class
D) Dictionary
Answer: C
9. Which of the following can not be used as a keyword of the Python programming
language?
A) pass
B) eval
C) assert
D) nonlocal
Answer: B
10. Which of the following operators can not be used in strings?
A) *
B) -
C) +
D) All of the mentioned
Answer: B
11. Which of the following is the maximum size of a Python identifier?
A) 32
B) 16
C) 128
D) No fixed length
Answer: D
12. Which of the following loops are not supported in the Python programming
language?
A) for
B) while
C) do-while
D) None of above
Answer: C
13. Which of the following is the correct way to declare a variable in Python?
A) int x = 10
B) x := 10
C) x = 10
D) var = 10
Answer: C
14. What is the perfect way to use a comment in the Python programming language?
A) //
B) /* */
C) #
D) None
Answer: C
15. Choose the wrong data type from the following:
A) int
B) string
C) char
D) list
Answer: C
16. Which operator should be used to concatenate two strings?
A) +
B) -
C) *
D) /
Answer: A
17. Which operator can be used to check data type in Python programming?
A) type()
B) typeof()
C) datatype()
D) check()
Answer: A
18. Why use input functions in Python?
A) Outputs data to the console
B) Reads input from the console
C) Allows reading from a file
D) Converts input into an integer
Answer: B
19. Which of the following is used to convert a string to an integer?
A) int(string)
B) str(string)
C) float(string)
D) convert(string)
Answer: A
20. How to skip the next iteration from a loop?
A) next
B) skip
C) continue
D) exit
Answer: C
21. What will be the output of the following code?
print(4 + 3 % 5)
A) 7
B) 2
C) 4
D) 1
Answer: A
22. What will be the output of the following code?
i = 1 while True: if i%3 == 0: break print(i) i += 1
A) 1 2 3
B) SyntaxError
C) 1 2
D) none of the mentioned
Answer: C
23. What will be the output of the following code? x << 2 (assuming x=1)
A) 4
B) 2
C) 1
D) 8
Answer: A
24. What will be the output of the following code?
print(2**(3**2))
print((2**3)**2)
print(2**3**2)
A) 512, 64, 512
B) 512, 512, 512
C) 64, 512, 64
D) 64, 64, 64
Answer: A
25. What will be the output of the following code?
l=[1, 0, 2, 0, 'hello', '', []]
print(list(filter(bool, l)))
A) [1, 0, 2, 'hello', '', []]
B) Error
C) [1, 2, 'hello']
D) [1, 0, 2, 0, 'hello', '', []]
Answer: C
26. What will be the output of the following code?
for i in [1, 2, 3, 4][::-1]: print(i, end=' ')
A) 4 3 2 1
B) error
C) 1 2 3 4
D) None of the mentioned
Answer: A
27. What will be the output of the following code?
class tester: def __init__(self, id): [Link] = str(id); id = "224"
temp = tester(12); print([Link])
A) 12
B) 224
C) None
D) Error
Answer: A
28. What will be the output of the following code?
list1 = [1, 3]; list2 = list1; list1[0] = 4; print(list2)
A) [1, 4]
B) [1, 3, 4]
C) [4, 3]
D) [1, 3]
Answer: C
29. What will be the output of the following code?
a = "4, 5"; nums = [Link](','); x, y = nums; int_prod = int(x) * int(y); print(int_prod)
A) 20
B) 45
C) 54
D) 4,5
Answer: A
30. What will be the output of the following code?
x = 5; if x == 5: print("Five") elif x > 3: print("Greater than three") else: print("Less than five")
A) Five
B) Greater than three
C) Less than five
D) None
Answer: A
31. Which method is used to define a function in Python?
A) def function_name[]:
B) def function_name():
C) function function_name():
D) func function_name():
Answer: B
32. How to invoke a function with a default argument in Python?
A) function_name(arg1, arg2)
B) function_name()
C) function_name(arg1)
D) function_name(arg1) when arguments are defined
Answer: B
33. How to define the length in Python?
A) length()
B) size()
C) len()
D) lengthof()
Answer: C
34. Which of the following is used to return a value from a function?
A) return value
B) return()
C) yield value
D) function(value)
Answer: A
35. Which of the following is used to add an element to a list?
A) [Link]()
B) [Link]()
C) [Link]()
D) [Link]()
Answer: B
36. Which of the following is an ordered collection?
A) set
B) tuple
C) dictionary
D) list
Answer: D
37. How to open a file in the Python programming language?
A) file()
B) openfile()
C) open()
D) fileopen()
Answer: C
38. Which of the following modes is apt for opening a Python file for writing?
A) r
B) w
C) a
D) x
Answer: B
39. How to manage an exception in Python programming?
A) try...except
B) catch...finally
C) except...try
D) try...catch
Answer: A
40. Which of the following is used to close a file in Python?
A) close(file)
B) [Link]()
C) [Link]()
D) end(file)
Answer: B
41. What will be the output of the code [i**2 for i in range(5)]?
A) [0, 1, 4, 9, 16]
B) [1, 4, 9, 16, 25]
C) [0, 1, 2, 3, 4]
D) [0, 2, 4, 6, 8]
Answer: A
42. Which of the following is true about tuples in Python?
A) Tuples are mutable
B) Tuples are immutable
C) Tuples cannot store multiple data types
D) Tuples cannot be nested
Answer: B
43. What will be the output of s = "python"; print(s[1:4])?
A) pyth
B) ytho
C) pth
D) yth
Answer: D
44. What is the purpose of the 'global' keyword in Python?
A) To modify a variable outside the current scope
B) To define a constant variable
C) To restrict a variable to the current scope
D) To import global modules
Answer: A
45. Which of the following is used to create a set in Python?
A) []
B) {}
C) ()
D) set[]
Answer: B
46. Which of the following is true about the 'with' statement in Python?
A) It is used to define a loop
B) It is used to handle exceptions only
C) It cannot be used with files
D) It ensures resources are properly closed after use
Answer: D
47. What is the purpose of the 'yield' keyword in Python?
A) To terminate a loop
B) To produce a value in a generator function
C) To define a class method
D) To raise an exception
Answer: B
48. What will be the output of print(3 * 'ab')?
A) ababab
B) abab
C) ab3
D) Error
Answer: A
49. What is the purpose of the 'is' operator in Python?
A) To check if two variables refer to the same object
B) To compare the values of two variables
C) To check if a variable is of a specific type
D) To perform a membership test
Answer: A
50. What is the purpose of the 'super()' function in Python?
A) To call a method from the parent class
B) To create a new instance of a class
C) To define a static method
D) To raise an exception
Answer: A