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 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 `__call__` in Python and what does implementing it on a class enable? 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 Python’s Method Resolution Order (MRO) and what algorithm computes it? 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 the output of the following? “`python import asyncio async def fetch(n): await asyncio.sleep(0) return n * 2 async def main(): results = await asyncio.gather(fetch(1), fetch(2), fetch(3)) print(results) asyncio.run(main()) “` Python DeveloperHard Try Now
What is the output of the following? “`python def make_adder(n): return lambda x: x + n adders = [make_adder(i) for i in range(3)] print(adders[0](10), adders[1](10), adders[2](10)) “` Python DeveloperHard Try Now
What is the output of the following? “`python class Validator: def __set_name__(self, owner, name): self.name = name def __set__(self, obj, value): if not isinstance(value, int): raise TypeError(f'{self.name} must be int’) obj.__dict__[self.name] = value class Point: x = Validator() y = Validator() p = Point() p.x = 5 p.x = ‘bad’ “` Python DeveloperHard Try Now