Python MCQ Questions
Python MCQ Questions are designed to test your knowledge and understanding of Python programming concepts. Covering a wide range of topics, including Python syntax, data types, functions, libraries, object-oriented programming, and more, these multiple-choice questions are perfect for learners at all levels. Whether you're preparing for exams, interviews, or simply improving your Python skills, these MCQs will help reinforce key concepts, enhance problem-solving abilities, and build confidence in Python programming.
Q1. What is the correct file extension for Python files?
A. a) .pyth
B. b) .python
C. c) .py
D. d) .p
π View Explanation
Q2. What will be the output of the following Python code?
```python
print(2 ** 3)
```
A. a) 5
B. b) 6
C. c) 8
D. d) 9
π View Explanation
Q3. Which of the following is not a valid Python data type?
A. a) list
B. b) tuple
C. c) set
D. d) dictionary
π View Explanation
Q4. What is the result of the following code snippet?
```python
x = [1, 2, 3]
x.append([4, 5])
print(len(x))
```
A. a) 3
B. b) 4
C. c) 5
D. d) 6
π View Explanation
Q5. Which of the following methods can be used to remove an item from a Python list?
A. a) remove()
B. b) delete()
C. c) pop()
D. d) Both a and c
π View Explanation
Q6. In Python, which of the following is used to define a block of code?
A. a) Parentheses ()
B. b) Curly braces {}
C. c) Indentation
D. d) Square brackets []
π View Explanation
Q7. What is the output of the following code?
```python
x = "Python"
print(x[0:2])
```
A. a) Py
B. b) Python
C. c) th
D. d) P
π View Explanation
Q8. Which Python module can be used to generate random numbers?
A. a) random
B. b) math
C. c) statistics
D. d) numpy
π View Explanation
Q9. What is the output of the following code?
```python
x = "Hello, World!"
print(x[7:])
```
A. a) Hello
B. b) World!
C. c) , World!
D. d) Hello,
π View Explanation
Q11. Which of the following is the correct extension for Python files?
A. .py
B. .python
C. .pt
D. .pyt
π View Explanation
Q12. Which keyword is used to define a function in Python?
A. def
B. function
C. func
D. define
π View Explanation
Q13. Which symbol is used for single-line comments in Python?
A. //
B. #
C. /* */
D. --
π View Explanation
Q14. Which data type is used to store text in Python?
A. int
B. str
C. bool
D. float
π View Explanation
Q15. Which of these is a valid Python variable name?
A. 2ndVar
B. _value
C. var-name
D. my var
π View Explanation
Q16. Which function prints output to the screen in Python?
A. echo()
B. print()
C. printf()
D. write()
π View Explanation
Q17. Which of the following is NOT a Python data type?
A. List
B. Tuple
C. Character
D. Dictionary
π View Explanation
Q19. Which loop executes as long as a condition is True?
A. for
B. while
C. do-while
D. foreach
π View Explanation
Q20. Which keyword is used to handle exceptions in Python?
A. test
B. try
C. catch
D. handle
π View Explanation
Q21. Which of these is used to create a list in Python?
A. {1,2,3}
B. [1,2,3]
C. (1,2,3)
D. <1,2,3>
π View Explanation
Q22. Which function returns the length of a string or list?
A. length()
B. size()
C. len()
D. count()
π View Explanation
Q23. Which keyword is used to create a class in Python?
A. class
B. object
C. def
D. module
π View Explanation
Q24. Which method adds an element to the end of a list?
A. add()
B. append()
C. insert()
D. extend()
π View Explanation
Q25. Which of the following is used for multi-line comments in Python?
A. /* */
B. //
C. """ """
D. #
π View Explanation
Q26. Which function converts a string to an integer?
A. int()
B. str()
C. float()
D. convert()
π View Explanation
Q27. Which operator checks equality of two values in Python?
A. =
B. ==
C. ===
D. !=
π View Explanation
Q28. Which keyword is used to exit a loop prematurely?
A. exit
B. stop
C. break
D. return
π View Explanation
Q29. Which function reads input from the user?
A. scanf()
B. input()
C. read()
D. get()
π View Explanation
Q30. Which method converts all characters in a string to uppercase?
A. upper()
B. uppercase()
C. toUpperCase()
D. toupper()
π View Explanation