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