ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(list(range(10, 0, -3)), list(range(0, -7, -2)), len(range(5, 5)), range(3)[1:])
- A. [10, 7, 4, 1] [0, -2, -4, -6] 0 [1, 2]
- B. [10, 7, 4] [0, -2, -4] 0 range(1, 3)
- C. [10, 7, 4, 1] [0, -2, -4, -6] 1 range(1, 3)
- D. [10, 7, 4, 1] [0, -2, -4, -6] 0 range(1, 3)
Correct answer: D. [10, 7, 4, 1] [0, -2, -4, -6] 0 range(1, 3)
A range with a negative step stops before the end value. Slicing a range returns another range object, so range(3)[1:] prints as range(1, 3).
More Python Programming questions
- What is printed? python s = 'abc' print(s.center(7, ''), s.zfill(5), '-'.join(['x']), s.ljust(2, '.'))
- What is printed? python print(divmod(-9, 4), -9 // 4, -9 % 4, round(-9 / 4))
- What is printed? python d = {'x': 1} e = d d = dict(d) d['x'] = 2 print(e['x'], d['x'])
- What is printed? python nums = [3, 3, 1] print(nums.index(3), nums.count(3), [i for i, v in enumerate(nums) if v == 3])
- What is printed? python print(int('0b1011', 2), int('0b1011', 0), int('z', 36), int('1011', 2))
- What is printed? python h = 0 for ch in 'abc': h = (h 31 + ord(ch)) % 1000 print(h, (-7) % 1000, (-7 31) % 1000)