ProgrammingModerateGATE CS & IT · Infosys
What is printed?
What is printed?
a, b = 5, 9 a ^= b b ^= a a ^= b print(a, b)
- A. 9 5
- B. 5 9
- C. 0 14
- D. 9 9
Correct answer: A. 9 5
Three XOR steps swap two values without a temporary variable. After them a holds 9 and b holds 5.
More Python Programming questions
- What is printed? python nums = [10, 9, 100, 1] print(sorted(nums, key=str), max(nums, key=str), sorted(map(str, nums))[-1])
- What is printed? python def ngecirc(a): n = len(a) res = [-1] n st = [] for i in range(2 n): x = a[i % n] while st and a[st[-1]] < x…
- What is printed? python def dsum(n): return n if n < 10 else dsum(sum(map(int, str(n)))) print(dsum(9875), dsum(0), dsum(999999999999))
- What is printed? python def lcp(words): out = [] for col in zip(words): if len(set(col)) == 1: out.append(col[0]) else: break return…
- What is printed? python s = 'abc' 2 + 'd' print(s[::3], 'bcd' in s, s.index('c', 3))
- What is printed? python print(range(0, 10, 3) == range(0, 11, 3), range(0, 10, 3)[-1], len(range(1018)))