ProgrammingEasyInfosys · Accenture · Capgemini pattern
Which keyword turns an ordinary Python function into a generator function?
- A. yield
- B. lambda
- C. async
- D. return
Correct answer: A. yield
Any function whose body contains yield is a generator function: calling it returns a generator object that produces values lazily, one per next().
More Python Programming questions
- What is printed? python x = [1, 2, 3] x.append([4, 5]) print(len(x))
- What is printed? python print(2 3 2)
- What is printed? python print(-7 // 2, -7 % 2)
- What is printed? python a = [1, 2, 3] b = a b += [4] print(a)
- What is printed? python print(bool("False"), bool(""), bool(0.0))
- What is printed? python nums = [3, 1, 2] print(nums.sort())