What is the output of the following? “`python class Meta(type): def __new__(mcs, name, bases, ns): ns[‘greeting’] = lambda self: f’Hello from {name}’ return super().__new__(mcs, name, bases, ns) class MyClass(metaclass=Meta): pass obj = MyClass() print(obj.greeting()) “` Python DeveloperHard Try Now
What does `itertools.chain(*iterables)` do and how is it more efficient than concatenation? Python DeveloperHard Try Now
What is a Python context manager and what dunder methods must a class implement to support `with`? Python DeveloperHard Try Now
What is the output of the following? “`python from functools import reduce result = reduce(lambda acc, x: acc + x, [1, 2, 3, 4, 5]) print(result) “` Python DeveloperHard Try Now
What is the output of the following? “`python gen = (x * 2 for x in range(4)) print(next(gen)) print(next(gen)) “` Python DeveloperHard Try Now
What is the difference between `__str__` and `__repr__` in Python classes? Python DeveloperHard Try Now
What does `functools.wraps` do when applied to a decorator wrapper function? Python DeveloperHard Try Now
What is the output of the following? “`python result = [x**2 for x in range(5) if x % 2 == 0] print(result) “` Python DeveloperHard Try Now
What is Python’s Global Interpreter Lock (GIL) and what problem does it create for CPU-bound multi-threaded programs? Python DeveloperHard Try Now
What is the output of the following? “`python def foo(a, b=[]): b.append(a) return b print(foo(1)) print(foo(2)) “` Python DeveloperHard Try Now
What is the output of the following code? “`python x = [1, 2, 3] y = x y.append(4) print(x) “` Python DeveloperHard Try Now
What does `zip([1,2,3], [‘a’,’b’,’c’])` produce when converted to a list? Python DeveloperEasy Try Now