ProgrammingModerateGATE CS · Product-company placement
What is printed?
What is printed?
a = [1, 2, 3, 4] b = a a = a.extend([5]) or a print(a is b, b[-1], [].extend([1]))
- A. False 5 None
- B. True 5 None
- C. True 4 None
- D. True 5 [1]
Correct answer: B. True 5 None
extend mutates in place and returns None, so `None or a` evaluates to a itself, the same object as b. extend on a temporary list also returns None.
More Python Programming questions
- What is printed? python s = "Mississippi" print(s.count("ss"), s.count("issi"), s.replace("ss", "S"), s.lower().index("s", 4))
- What is printed? python print("a" "b" 2, ("a" + "b") 2, "-".join(["a", "b"]) 2, "x".join("123"))
- What is printed? python s = "abc" print(repr(s[1:1] + s[3:] + s[-1:-2]), s[0:0] == s[5:9], len(s[-5:5]), s[True:])
- What is printed? python w = ["bob", "Al", "al", "Bo"] print(sorted(w), sorted(w, key=str.lower))
- What is printed? python people = [("ann", 30), ("bob", 25), ("cid", 30), ("dan", 25)] people.sort(key=lambda p: p[0], reverse=True)…
- What is printed? python nums = [4, -1, 3, -1, 2] print(sorted(nums, key=lambda v: (v < 0, -v)), sorted(set(nums), reverse=True)[:2])