ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print([1, 2] < [1, 2, 0], (1, 2) < (1, 2, 0), 'abc' < 'abd', [2] < [1, 9])
- A. False True True False
- B. True True True False
- C. True False True False
- D. True True True True
Correct answer: B. True True True False
A shorter sequence that is a prefix of a longer one compares as smaller for both lists and tuples. Strings compare by code point, and [2] < [1, 9] is decided by the first elements, 2 < 1, which is False.
More Python Programming questions
- What is printed? python x = [1, 2, 3, 4] y = x x = x + [5] x.append(6) y.append(9) print(len(x), len(y), y is x)
- What is printed? python from collections import Counter c = Counter([3, 1, 3, 2, 1, 3]) print(c.mostcommon(1), sorted(c.elements()), c[7])
- What is printed? python from math import comb print(comb(5, 2), comb(5, 7), comb(0, 0), comb(3, 1) comb(3, 1))
- What is printed? python x = 0 total = 0 for i in range(1, 6): if i % 2: continue x += i if x > 4: break else: total = -1 print(x, total)
- What is printed? python def f(n): if n <= 1: return n return f(n - 1) + f(n - 2) print(f(20), f.defaults)
- What is printed? python s = 'abcabc' print(s.index('c'), s.rindex('a'), s.find('bca', 1), s.count('bc', 1, 4))