ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
x = 7
match x:
case 1 | 2:
r = 'small'
case int(v) if v > 5:
r = f'big{v}'
case _:
r = 'other'
print(r)- A. big7
- B. small
- C. other
- D. 7
Correct answer: A. big7
The first pattern fails for 7. The class pattern int(v) binds v to 7, and the guard v > 5 holds, so the second branch runs and gives 'big7'.
More Python Programming questions
- What is printed? python a = [[1, 2], [3]] b = a[:] b[1].append(4) b.append([5]) print(a, b, len(a))
- What is printed? python print(bool([]), bool([0]), bool(0.0), bool('False'), bool(None) or 'x')
- What is printed? python import heapq events = [(3, 'end'), (1, 'start'), (2, 'mid')] heapq.heapify(events) out = [] while events: t, name…
- What is printed? python word = 'level' print(word == word[::-1], 'ab' 2 == 'abab', list('ab') == ['a', 'b'], ('a',) 0 == ())
- 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…