ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
s = {1, 2, 3}
t = s
t |= {4}
u = s | {5}
print(len(s), len(u), t is s)- A. 3 4 True
- B. 4 4 False
- C. 3 5 True
- D. 4 5 True
Correct answer: D. 4 5 True
|= on a set mutates it in place, so s and t are the same object with four items. | creates a new set, which has five items.
More Python Programming questions
- What is printed? python def gen(): x = yield 1 print('got', x) yield 2 g = gen() print(next(g)) print(g.send('hi'))
- What is printed? python print(sum(1 for c in 'Mississippi' if c in 'aeiou'), 'Mississippi'.count('ss'), 'Mississippi'.rfind('ss'))
- What is printed? python from math import prod print(prod([]), prod([2, 3, 4]), prod([1.5, 2]))
- What is printed? python print(list(range(10, 0, -3)), list(range(0, -7, -2)), len(range(5, 5)), range(3)[1:])
- What is printed? python s = 'abc' print(s.center(7, ''), s.zfill(5), '-'.join(['x']), s.ljust(2, '.'))
- What is printed? python print(divmod(-9, 4), -9 // 4, -9 % 4, round(-9 / 4))