ProgrammingModerateTCS NQT · Infosys pattern
What is printed?
What is printed?
a = 256; b = 256 c = [1, 2]; d = [1, 2] print(a == b, c == d, c is d, c[:] is c)
- A. True True False False
- B. True True True False
- C. True False False False
- D. True True False True
Correct answer: A. True True False False
== compares values: equal ints and equal lists. 'is' compares identity: two list literals create two objects, and slicing creates a new list too. (Avoid relying on 'is' for numbers; small-int caching is an implementation detail.)
More Python Programming questions
- What is printed? python t = (1, [2, 3], 4) try: t[1] += [5] except TypeError as e: print("error", end=" ") print(t)
- What is printed? python def f(): try: return "try" finally: print("finally", end=" ") def g(): try: return "try" finally: return "finally"…
- What is printed? python nums = [3, 1, 2] r = nums.sort() s = sorted(nums, reverse=True) print(r, nums, s)
- What is printed? python x = 10 def outer(): x = 20 def inner(): nonlocal x x += 1 return x return inner() + x print(outer(), x)
- What is printed? python d = {} d[1] = "a" d[1.0] = "b" d[True] = "c" print(d, len(d))
- What is printed? python a = [1, 2, 3, 4, 5, 6] for x in a: if x % 2 == 0: a.remove(x) print(a)