Python MCQs - 25 Multiple Choice Questions
1. What is the output of print(2 ** 3)?
A) 6
B) 8
C) 9
D) None of the above
Answer: B
A) 6
B) 8
C) 9
D) None of the above
Answer: B
2. Which of the following is a mutable data type in Python?
A) Tuple
B) String
C) List
D) None of the above
Answer: C
A) Tuple
B) String
C) List
D) None of the above
Answer: C
3. What keyword is used to define a function in Python?
A) func
B) define
C) def
D) function
Answer: C
A) func
B) define
C) def
D) function
Answer: C
4. Which of the following is used for comments in Python?
A) // comment
B) /* comment */
C) # comment
D)
Answer: C
A) // comment
B) /* comment */
C) # comment
D)
Answer: C
5. What is the correct file extension for Python files?
A) .p
B) .pyth
C) .python
D) .py
Answer: D
A) .p
B) .pyth
C) .python
D) .py
Answer: D
6. Which function is used to read input from the user in Python?
A) input()
B) read()
C) scan()
D) getInput()
Answer: A
A) input()
B) read()
C) scan()
D) getInput()
Answer: A
7. How do you create a list in Python?
A) list(){}
B) []
C) ()
D) list{}
Answer: B
A) list(){}
B) []
C) ()
D) list{}
Answer: B
8. What does the 'len()' function do?
A) Returns the length of an object
B) Returns the type of an object
C) Returns the size of an object
D) None of the above
Answer: A
A) Returns the length of an object
B) Returns the type of an object
C) Returns the size of an object
D) None of the above
Answer: A
9. Which of the following is not a valid variable name in Python?
A) my_var
B) 2nd_variable
C) _myVar
D) myVar2
Answer: B
A) my_var
B) 2nd_variable
C) _myVar
D) myVar2
Answer: B
10. What is the purpose of the 'pass' statement in Python?
A) To terminate a loop
B) To create a placeholder
C) To raise an exception
D) None of the above
Answer: B
A) To terminate a loop
B) To create a placeholder
C) To raise an exception
D) None of the above
Answer: B
11. Which of the following keywords is used to handle exceptions in Python?
A) catch
B) try
C) handle
D) except
Answer: B
A) catch
B) try
C) handle
D) except
Answer: B
12. What will be the output of print(type([]))?
A) class 'list'
B) class 'tuple'
C) class 'dict'
D) class 'set'
Answer: A
A) class 'list'
B) class 'tuple'
C) class 'dict'
D) class 'set'
Answer: A
13. Which of the following is a Python built-in data type?
A) List
B) Dictionary
C) Set
D) All of the above
Answer: D
A) List
B) Dictionary
C) Set
D) All of the above
Answer: D
14. How do you start a while loop in Python?
A) while x = 10:
B) while (x < 10):
C) while x < 10:
D) while (x < 10):
Answer: C
A) while x = 10:
B) while (x < 10):
C) while x < 10:
D) while (x < 10):
Answer: C
15. Which of the following operators is used for exponentiation in Python?
A) ^
B) **
C) ^^
D) exp()
Answer: B
A) ^
B) **
C) ^^
D) exp()
Answer: B
16. How do you create a dictionary in Python?
A) {}
B) []
C) ()
D) dict[]
Answer: A
A) {}
B) []
C) ()
D) dict[]
Answer: A
17. What does the 'append()' method do?
A) Adds an element to the end of a list
B) Removes an element from a list
C) Sorts the list
D) None of the above
Answer: A
A) Adds an element to the end of a list
B) Removes an element from a list
C) Sorts the list
D) None of the above
Answer: A
18. Which of the following statements is true about Python lists?
A) Lists are immutable
B) Lists can contain mixed data types
C) Lists cannot be nested
D) None of the above
Answer: B
A) Lists are immutable
B) Lists can contain mixed data types
C) Lists cannot be nested
D) None of the above
Answer: B
19. What is the output of print(bool(0))?
A) True
B) False
C) None
D) 0
Answer: B
A) True
B) False
C) None
D) 0
Answer: B
20. Which module in Python is used for regular expressions?
A) re
B) regex
C) regexp
D) re_mod
Answer: A
A) re
B) regex
C) regexp
D) re_mod
Answer: A
21. What is the output of print("Hello"[1])?
A) H
B) e
C) l
D) o
Answer: B
A) H
B) e
C) l
D) o
Answer: B
22. How do you define a class in Python?
A) class MyClass:
B) define MyClass:
C) MyClass(){}
D) MyClass:
Answer: A
A) class MyClass:
B) define MyClass:
C) MyClass(){}
D) MyClass:
Answer: A
23. Which of the following functions can be used to convert a string to an integer?
A) int()
B) str()
C) float()
D) convert()
Answer: A
A) int()
B) str()
C) float()
D) convert()
Answer: A
24. What will be the output of print("Hello" + " World")?
A) Hello World
B) HelloWorld
C) Error
D) Hello+World
Answer: A
A) Hello World
B) HelloWorld
C) Error
D) Hello+World
Answer: A
25. What is the purpose of the 'break' statement in Python?
A) To terminate a loop
B) To skip the current iteration
C) To stop the program
D) None of the above
Answer: A
A) To terminate a loop
B) To skip the current iteration
C) To stop the program
D) None of the above
Answer: A
1 Comments
Very informative,good job👏👏
ReplyDelete