ProgrammingHardHCL · Tech Mahindra · Python placement
What does the following Python 3 code print? def f(): for i in range(3): if i == 1: continue print(i, end="") print() f()
- A. 0 2
- B. 012
- C. 01
- D. 02
Correct answer: D. 02
continue skips printing when i==1, so only i=0 and i=2 are printed (with no separator, since end="").
More Python Programming questions
- What does the following Python 3 code print? def f(): for i in range(5): if i == 3: break else: print("else-no-break") print(i) f()
- What does the following Python 3 code print? def f(): for i in range(3): pass else: print("else-ran") f()
- What does the following Python 3 code print? while False: print("never") else: print("while-else")
- What does the following Python 3 code print? x = 1 while x < 5: x += 1 if x == 3: break else: print("no-break") print(x)
- What does the following Python 3 code print? print([i for i in range(5) if i != 2][::-1])
- What does the following Python 3 code print? matrix = [[1, 2], [3, 4], [5, 6]] transposed = [[row[i] for row in matrix] for i in range(2)]…