Python Professional — Hard
Ready to go further?
Related questions
- What is the difference between @staticmethod and a module-level function, and when should you prefer one over the other?
- What is the key difference between an iterator and an iterable in Python?
- What does the following code output? import asyncio async def producer(queue): for i in range(3): await queue.put(i) await queue.put(None) async def consumer(queue): while True: item = await queue.get() if item is None: break print(item) async def main(): q = asyncio.Queue() await asyncio.gather(producer(q), consumer(q)) asyncio.run(main())
- Which of the following correctly explains how Python's asyncio event loop executes coroutines?
- What does the following code output? from abc import ABC, abstractmethod class Animal(ABC): @abstractmethod def speak(self): ... def describe(self): return f'I say {self.speak()}' class Dog(Animal): def speak(self): return 'woof' print(Dog().describe())
- What is the output of the following? import weakref class Obj: pass obj = Obj() ref = weakref.ref(obj) print(ref() is obj) del obj print(ref())
