AI VOID
AI
PROJECTS
BLOG
MORE ▼
HOW IT WORKS
COMPARISONS
CHEATSHEETS
INTERVIEWS
NEWS
CUT THE CHASE
TUTORIALS
TROUBLESHOOTING
TAGS
CATEGORIES
▦
AI
PROJECTS
BLOG
HOW IT WORKS
COMPARISONS
CHEATSHEETS
INTERVIEWS
NEWS
CUT THE CHASE
TUTORIALS
TROUBLESHOOTING
TAGS
CATEGORIES
Python Core Concepts - MCQ Practice Test
Test your Python core concepts knowledge with this MCQ practice quiz for interview preparation.
Question 1
Which of the following data types is mutable in Python 3.12?
str
tuple
list
int
Question 2
What is the output of this code? def my_function(a, b=[]): b.append(a) return b print(my_function(1)) print(my_function(2)) print(my_function(3, [])) print(my_function(4))
[1] [2] [3] [4]
[1] [1, 2] [3] [3, 4]
[1] [1, 2] [3] [1, 2, 4]
[1] [1, 2] [3] [1, 2, 3, 4]
Question 3
Which of the following correctly describes the purpose of the __init__ method in a Python 3.12 class?
It is called automatically when an object is destroyed.
It is a special method used for comparing two objects for equality.
It is the constructor method, called automatically when a new object is created.
It defines how an object should be converted to a string representation.
Question 4
What will be the output of this code? x = 10 def outer(): x = 20 def inner(): nonlocal x x = 30 inner() print(x) outer() print(x)
20 10
30 10
30 30
20 20
Question 5
Which of the following is NOT a valid way to create a set in Python 3.12?
my_set = {1, 2, 3}
my_set = set([1, 2, 3])
my_set = {}
my_set = set()
Question 6
In Python 3.12, what is the purpose of a generator function?
To create a function that automatically caches its results.
To define an iterator that produces values on-the-fly, pausing execution until the next value is requested.
To enable multiple threads to run concurrently within a single function.
To handle exceptions and gracefully recover from errors.
Question 7
Which of the following statements about Python's Global Interpreter Lock (GIL) (as of Python 3.12) is true?
The GIL allows multiple threads to execute Python bytecodes concurrently on multiple CPU cores.
The GIL is a mechanism that prevents race conditions by locking global variables.
The GIL ensures that only one thread can execute Python bytecode at a time within a single process.
The GIL primarily impacts I/O-bound operations by making them single-threaded.
Question 8
What is the correct way to handle a KeyError when trying to access a dictionary element in Python 3.12, providing a default value if the key is not found?
my_dict = {'a': 1} value = my_dict['b'] if 'b' in my_dict else 0
my_dict = {'a': 1} try: value = my_dict['b'] except KeyError: value = 0
my_dict = {'a': 1} value = my_dict.get('b', 0)
All of the above are equally efficient and Pythonic.
Submit Answers
Try Again
Your Results
Score:
0
/
0
(
0
%)