ProgrammingModerateTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
x = 'aaa' y = list(x) y[0] = 'b' print(x, ''.join(y), x is y)
- A. aaa baa False
- B. baa baa False
- C. aaa aaa False
- D. aaa baa True
Correct answer: A. aaa baa False
Strings are immutable, so x is unchanged. list(x) builds a new list, so changing its first item gives 'baa' and x is y is False.
More Python Programming questions
- What is printed? python grid = [[1, 2], [3, 4]] flat = [v for row in grid for v in row] print(flat, sum(flat) == sum(map(sum, grid)))
- What is printed? python def merge(a, b): out, i, j = [], 0, 0 while i < len(a) and j < len(b): if a[i] <= b[j]: out.append(a[i]); i += 1…
- Which change removes the RecursionError for a DFS over a path of 10^5 nodes, while keeping the same visiting order?
- What is printed? python words = ['apple', 'bob', 'kayak', 'tree'] print([w for w in words if w == w[::-1]], len(words[1:3]))
- What is printed? python lines = ['3 4', '10 20'] pairs = [tuple(map(int, ln.split())) for ln in lines] print(pairs, sum(a b for a, b in…
- What is printed? python from math import comb print(comb(4, 2) comb(4, 2), comb(8, 4) - comb(8, 3))