Python Professional — Hard
Ready to go further?
Related questions
- What does the following code output? from typing import TypeVar, Generic T = TypeVar('T') class Stack(Generic[T]): def __init__(self): self._items: list[T] = [] def push(self, item: T) -> None: self._items.append(item) def pop(self) -> T: return self._items.pop() s: Stack[int] = Stack() s.push('not an int') print(s.pop())
- What is the purpose of Python's __buffer__ protocol (PEP 688, Python 3.12) and the Buffer abstract base class?
- What is the purpose of sys.settrace() and how does it work?
- What is the difference between concurrent.futures.ProcessPoolExecutor and ThreadPoolExecutor for CPU-bound tasks?
- What does the following code output? from itertools import groupby data = [('a', 1), ('a', 2), ('b', 3), ('a', 4)] for key, group in groupby(data, key=lambda x: x[0]): print(key, list(group))
- What does the following code output? class Descriptive: def __get__(self, obj, objtype=None): return 42 if obj is None else obj.__dict__.get('_val', 0) def __set__(self, obj, value): obj.__dict__['_val'] = value class MyClass: attr = Descriptive() print(MyClass.attr)
