ProgrammingVery hardCAT · MBA placement
What is printed?
What is printed?
print(range(0, 10, 3) == range(0, 11, 3), range(0, 10, 3)[-1], len(range(10**18)))
- A. False 9 1000000000000000000
- B. True 10 1000000000000000000
- C. True 9 1000000000000000000
- D. True 9 1000000000000000001
Correct answer: C. True 9 1000000000000000000
Two ranges compare equal when they produce the same values, and range(0, 10, 3) and range(0, 11, 3) both give 0, 3, 6 and 9. Indexing and len take constant time.
More Python Programming questions
- What is printed? python s = 'abc' t = s s += 'd' u = list('abc') v = u u += ['d'] print(s, t, u is v, v)
- What is printed? python print(bin(0b1011011).count('1'), (0b1011011).bitcount(), 0b1011011 & (0b1011011 - 1))
- What is printed? python def f(n): c = 0 while n: n &= n - 1 c += 1 return c print(f(255), f(-1 & 0xFF), f(0))
- What is printed? python s = 'abc' print(s[::-1] + s[0], s[1:] + s[:1], s[-1] + s[-2:])
- What is printed? python print(len('é'), len('é'.encode()), len(f'{"é":>3}'), len(str(0.1 + 0.2)))
- What is printed? python print('%-6s|' % 'ab', '%6.2f|' % 3.14159, '%+.1e' % 12345.6789)