Python Multiple Choice Questions (MCQs)
1. Fundamentals
Q1. What is the maximum possible length of an identifier in Python?
- A) 31 characters
- B) 63 characters
- C) 79 characters
- D) None of the above
Answer: D. Identifiers can be of any length in Python.
Q2. Which of the following is the correct extension of the Python file?
- A) .python
- B) .pl
- C) .py
- D) .p
Answer: C. Python files typically end with the .py extension.
2. Data Structures
Q3. Which of these about a dictionary is false?
- A) The values of a dictionary can be accessed using keys
- B) The keys of a dictionary can be accessed using values
- C) Dictionaries aren't ordered
- D) Dictionaries are mutable
Answer: B. You cannot directly access keys using values in a dictionary because values are not guaranteed to be unique and are not indexed.
Q4. What is the output of print(type([]))?
- A)
<class 'list'> - B)
<class 'array'> - C)
<type 'list'> - D)
<type 'array'>
Answer: A. In Python 3, it outputs <class 'list'>.
3. Advanced Python
Q5. Which keyword is used for exception handling in Python?
- A) try
- B) catch
- C) except
- D) A and C
Answer: D. Python uses try blocks to wrap code that may throw exceptions, and except blocks to handle those exceptions.