What is the difference between asyncio.gather() and asyncio.TaskGroup (Python 3.11+)? Python ProfessionalHard Try Now
Which of the following correctly explains how Python’s asyncio event loop executes coroutines? Python ProfessionalHard Try Now
What is the output of the following code involving __missing__? class DefaultList(dict): def __missing__(self, key): self[key] = [] return self[key] d = DefaultList() d[‘a’].append(1) d[‘a’].append(2) d[‘b’].append(3) print(d) Python ProfessionalHard Try Now
What does the following descriptor code output? class Validator: def __set_name__(self, owner, name): self.name = name def __get__(self, obj, objtype=None): if obj is None: return self return obj.__dict__.get(self.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() p = Point() p.x = 5 print(p.x) Python ProfessionalHard Try Now
What is the output of the following code? class Meta(type): def __new__(mcs, name, bases, namespace): namespace[‘class_id’] = name.upper() return super().__new__(mcs, name, bases, namespace) class Foo(metaclass=Meta): pass print(Foo.class_id) Python ProfessionalHard Try Now
What does the following code output? from collections import namedtuple Point = namedtuple(‘Point’, [‘x’, ‘y’]) p = Point(3, 4) print(p.x, p[1], len(p)) Python DeveloperMedium Try Now
What does the following code output? def make_adder(n): return lambda x: x + n add5 = make_adder(5) print(add5(3), add5(10)) Python DeveloperMedium Try Now
What is the difference between append() and extend() on a Python list? Python DeveloperMedium Try Now
What is the output of the following? class A: x = 5 a1 = A() a2 = A() a1.x = 10 print(A.x, a1.x, a2.x) Python DeveloperMedium Try Now
What does Python’s super() return and why is it preferred over calling the parent class directly? Python DeveloperMedium Try Now
What does the following code output? from itertools import islice g = (x**2 for x in range(100)) print(list(islice(g, 4))) Python DeveloperMedium Try Now
What is the output of the following? x = {1, 2, 3} & {2, 3, 4} print(x) Python DeveloperMedium Try Now