What is the output of the following? try: x = 1 / 0 except ZeroDivisionError: x = -1 finally: print(x) Python DeveloperMedium Try Now
What is the output of the following? “`python class MyContext: def __enter__(self): print(‘enter’) return self def __exit__(self, exc_type, exc_val, exc_tb): print(‘exit’) return True with MyContext(): print(‘inside’) raise ValueError(‘oops’) print(‘after’) “` Python DeveloperHard Try Now
What is the output of the following? “`python gen = (x for x in range(10) if x % 3 == 0) result = list(gen) print(result) print(list(gen)) “` Python DeveloperHard Try Now
What is the Python `match` statement (structural pattern matching, Python 3.10+) and how does it differ from a chain of `if/elif`? Python DeveloperHard Try Now
What is the output of the following? “`python from functools import partial def power(base, exp): return base ** exp square = partial(power, exp=2) cube = partial(power, exp=3) print(square(4), cube(3)) “` Python DeveloperHard Try Now
What is the output of the following? “`python class EventMixin: def trigger(self, name): handler = getattr(self, f’on_{name}’, None) if callable(handler): return handler() return None class App(EventMixin): def on_start(self): return ‘started’ app = App() print(app.trigger(‘start’)) print(app.trigger(‘stop’)) “` Python DeveloperHard Try Now
What is the difference between `multiprocessing.Pool.map()` and `multiprocessing.Pool.imap()` for large datasets? Python DeveloperHard Try Now
What is `__call__` in Python and what does implementing it on a class enable? Python DeveloperHard Try Now
What is the output of the following? “`python from typing import get_type_hints def greet(name: str, age: int) -> str: return f'{name} is {age}’ print(get_type_hints(greet)) “` Python DeveloperHard Try Now
What is the output of the following? “`python import sys print(sys.getrefcount([1,2,3])) “` Python DeveloperHard Try Now
What is the output of the following? “`python class MyList(list): def append(self, item): super().append(item * 2) m = MyList() m.append(3) m.extend([4, 5]) print(m) “` Python DeveloperHard Try Now
What is the output of the following? “`python class Singleton: _instance = None def __new__(cls, *args, **kwargs): if cls._instance is None: cls._instance = super().__new__(cls) return cls._instance a = Singleton() b = Singleton() print(a is b) “` Python DeveloperHard Try Now
What is the output of the following? “`python from collections import Counter c = Counter(‘aabbccca’) print(c.most_common(2)) “` Python DeveloperHard Try Now
What is Python’s Method Resolution Order (MRO) and what algorithm computes it? Python DeveloperHard Try Now