10/218 questions · Unlock full access
Q1

A financial services company is developing a framework where different asset classes must be represented. A base `Asset` class is defined. `Stock` and `Bond` classes inherit from `Asset`. A `Portfolio` class is then created, which holds a collection of `Asset` objects. Which two primary OOP principles are demonstrated by the `Portfolio` class's relationship with the `Asset`, `Stock`, and `Bond` classes?

Q2

A developer needs to create a decorator that accepts an argument, for example, `@retry(attempts=3)`. Which code structure correctly implements a decorator that takes its own arguments?

Q3

You are reviewing Python code and find the following line inside an `except` block: `raise ConnectionError("Failed to connect to database") from exc` What is the primary purpose of the `from exc` syntax in this context?

Q4

A developer is writing a REST client using the `requests` library to fetch user data from an API endpoint. The API requires a custom header `X-API-Key` for authentication. Which code snippet correctly sends a GET request to `https://api.example.com/users/123` with the required custom header?

Q5

According to PEP 8, what is the recommended way to check if a list named `my_list` is empty?

Q6

A developer is using the `csv` module to write data to a file. They want to ensure that each row is written from a dictionary, where the dictionary keys correspond to the header row. Which combination of `csv` module components should be used to open the file and write the rows?

Q7

When designing a GUI with `tkinter`, what is the fundamental difference between the `grid` and `place` geometry managers?

Q8

A developer needs to create a custom class that behaves like a dictionary but logs a message every time a key is accessed. Which magic method must be implemented to intercept key retrieval?

Q9

What is the primary motivation for using the `shelve` module over the `pickle` module for object persistence?

Q10

True or False: In Python's `socket` module, TCP sockets are created using `socket.SOCK_DGRAM` and UDP sockets are created using `socket.SOCK_STREAM`.