ProgrammingModerateTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
s = {1, 2, 3}
s |= {3, 4}
s.discard(9)
print(sorted(s), 4 in s, len(s))- A. [1, 2, 3, 4] False 4
- B. [1, 2, 3] True 3
- C. [1, 2, 3, 4] True 3
- D. [1, 2, 3, 4] True 4
Correct answer: D. [1, 2, 3, 4] True 4
|= adds 4 to the set, and the duplicate 3 is ignored. discard on a missing item does nothing. The set has four items.
More Python Programming questions
- What is printed? python nums = [5, 3, 8] nums2 = nums nums += [1] nums3 = nums[:] nums3.pop() print(nums2, nums3)
- What is printed? python from math import gcd print(gcd(0, 5), gcd(-4, 6), gcd(0, 0))
- What is printed? python x = 12 x //= 5 y = 12 y /= 5 print(x, y, type(x).name, type(y).name)
- What is printed? python import itertools print(list(itertools.islice(itertools.cycle('ab'), 5)), list(itertools.repeat(7, 2)))
- What is printed? python def f(): yield 1 yield 2 print(sum(f()), max(f()), list(zip(f(), f())))
- What is printed? python s = 'a-b-c' print(s.split('-', 1), s.rsplit('-', 1)[-1], s.partition('-')[2])