ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(3 in range(5), 5 in range(5), range(0, 6, 2) == range(0, 7, 2), list(range(3, 0, -1)))
- A. True False False [3, 2, 1]
- B. True False True [3, 2, 1]
- C. True True False [3, 2, 1]
- D. True False False [1, 2, 3]
Correct answer: A. True False False [3, 2, 1]
range(0, 6, 2) holds 0, 2, 4 and range(0, 7, 2) holds 0, 2, 4, 6, so they are not equal. Membership in range is True for 3 and False for 5, and a range counting down from 3 gives 3, 2, 1.
More Python Programming questions
- What is printed? python print(10 % 4 == 2, -10 % 4 == 2, 10 // -4, 10 / -4)
- What is printed? python s = 'abcdef' print(s[-2:], s[:-2], s[-10:], s[::-2][0])
- What is printed? python print('abc' < 'abd' and 'x' or 'y', [] or 'empty', 0 or 0.0 or 'z')
- What is printed? python print(len({'a': 1, 'a': 2}), {'a': 1, 'a': 2}, list({1, 2, 1}), sorted({3, 1, 2} & {2, 3, 4}))
- What is printed? python print('Ab'.swapcase(), 'ab'.capitalize() == 'Ab', 'AB'.lower() == 'ab', 'a b'.title())
- What is printed? python print(3 > 2 > 1, 3 > 2 and 2 > 1, (3 > 2) + (2 > 1))