ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
def f():
yield 1
yield 2
print(sum(f()), max(f()), list(zip(f(), f())))- A. 3 2 [(1, 1), (2, 2)]
- B. 3 2 [(1, 1)]
- C. 3 2 [(1, 2)]
- D. 6 2 [(1, 1), (2, 2)]
Correct answer: A. 3 2 [(1, 1), (2, 2)]
Each call to f() makes a new generator, so every use starts from 1. zip pairs the two fresh generators item by item.
More Python Programming questions
- What is printed? python s = 'a-b-c' print(s.split('-', 1), s.rsplit('-', 1)[-1], s.partition('-')[2])
- What is printed? python print(divmod(-1, 10), divmod(1, -10), -1 % 10)
- What is printed? python words = ['hi', 'there', 'hey'] print(max(words), min(words, key=len), sorted(words, key=lambda w: (len(w), w)))
- What is printed? python print(pow(0, 0), 0 0 == 1, pow(2, -2, 5), pow(0, 0, 5))
- What is printed? python import math print(0.0 == -0.0, 1 / float('-inf'), 2 -1074 / 2 == 0, math.copysign(0.0, -1))
- What is printed? python try: print(int('')) except ValueError: print('empty') try: print(0.0 / 0) except ZeroDivisionError: print('zero')