ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
def f():
yield 1
g = f()
print(type(f).__name__, type(g).__name__, hasattr(g, "__next__"), iter(g) is g, callable(g))- A. function generator True True False
- B. generator generator True True False
- C. function generator True False True
- D. function iterator True True False
Correct answer: A. function generator True True False
Calling a generator function returns a generator object, an iterator whose __iter__ returns itself. It is not callable.
More Python Programming questions
- What is printed? python class Matrix: def init(self, r): self.r = r def getitem(self, idx): i, j = idx return self.r[i][j] def…
- What is printed? python a = [1, 2, 3] b = a[:] print(a == b, a is b, a[:] is a[:], id(a) == id(b), a.copy() == list(a))
- A service catches errors with except Exception: around its main loop. Which of the following will NOT be caught by that handler?
- For a Python list a with n elements, which operation is O(n) in the worst case (not amortised O(1))?
- How many of these statements about CPython are correct? 1. A tuple is hashable only if all its elements are hashable. 2. x in someset is…
- In CPython, two threads each run a pure-Python CPU-bound loop (no I/O, no C extensions releasing the lock) on a 4-core machine. Compared…