ProgrammingModerateTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
d = {'x': 1}
e = d
d = dict(d)
d['x'] = 2
print(e['x'], d['x'])- A. 1 1
- B. 2 1
- C. 1 2
- D. 2 2
Correct answer: C. 1 2
dict(d) builds a new dictionary, so the later update applies only to the new object d. e still refers to the old dictionary, so its value stays 1.
More Python Programming questions
- What is printed? python nums = [3, 3, 1] print(nums.index(3), nums.count(3), [i for i, v in enumerate(nums) if v == 3])
- What is printed? python print(int('0b1011', 2), int('0b1011', 0), int('z', 36), int('1011', 2))
- What is printed? python h = 0 for ch in 'abc': h = (h 31 + ord(ch)) % 1000 print(h, (-7) % 1000, (-7 31) % 1000)
- What is printed? python print(sorted(['b2', 'a10', 'a9', 'b1'], key=lambda s: (s[0], int(s[1:]))), sorted(['b2', 'a10', 'a9', 'b1']))
- What is printed? python from math import isclose print(isclose(0, 1e-10), isclose(0, 1e-10, abstol=1e-9), isclose(1e9, 1e9 + 1)…
- What is printed? python x = 0b10110110 print(format(x, '08b')[::-1], x.bitcount(), x & (x - 1), (x & -x).bitlength())