ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
word = 'level'
print(word == word[::-1], 'ab' * 2 == 'abab', list('ab') == ['a', 'b'], ('a',) * 0 == ())- A. True True True True
- B. True False True True
- C. False True True True
- D. True True False True
Correct answer: A. True True True True
level reads the same backwards, so the first check holds. Repetition builds the same string, and list('ab') equals ['a', 'b']. Repeating a one-tuple zero times gives an empty tuple, which equals ().
More Python Programming questions
- What is printed? python parent = list(range(5)) def find(x): while parent[x] != x: parent[x] = parent[parent[x]] x = parent[x] return x…
- What is printed? python trie = {} for w in ['car', 'cat', 'dog']: node = trie for ch in w: node = node.setdefault(ch, {}) node['#'] = True…
- What is printed? python h = 0 for ch in 'abc': h = (h 31 + ord(ch)) % 1000 print(h)
- What is printed? python grid = ['a..', '.a.', '...'] cnt = sum(row.count('.') for row in grid) diag = ''.join(grid[i][i] for i in…
- What is printed? python from collections import Counter c = Counter('abracadabra') print(sum(v for v in c.values() if v % 2), len(c)…
- What is printed? python x = 0b1010 y = 0o17 z = 0xFF print(x ^ y, x | z, z >> 4, y & ~x)