ProgrammingHardTCS NQT · Infosys pattern
What is printed?
What is printed?
s1 = {1, 2, 3}
s2 = {2, 3, 4}
print(s1 - s2, s1 | s2, s1 & s2)- A. {1} {1,2,3,4} {2,3}
- B. {4} {1,2,3,4} {2,3}
- C. {1} {2,3} {1,2,3,4}
- D. {1,4} {1,2,3,4} {2,3}
Correct answer: A. {1} {1,2,3,4} {2,3}
- is set difference (elements only in s1: {1}). | is union ({1,2,3,4}). & is intersection ({2,3}).
More Python Programming questions
- What is printed? python print(all([1, 2, 3]), all([1, 0, 3]), any([0, 0, 0]), any([0, 1, 0]))
- What is printed? python x = None print(x or "default") y = 0 print(y or "default") z = "" print(z or "fallback")
- What is printed? python def gen(): try: x = yield 1 except GeneratorExit: print("closing") raise g = gen() next(g) g.close()
- What is printed? python a = 5 def outer(): x = 10 def inner(): nonlocal x x += a return x return inner() print(outer())
- What is printed? python class Temperature: def init(self, celsius=0): self.celsius = celsius @property def fahrenheit(self): return…
- What is printed? python def f(a, b, , c=10, kwargs): return a + b + c + sum(kwargs.values()) print(f(1, 2, d=3, e=4)) print(f(1, 2, c=100))