ProgrammingVery hardGATE CS · Product-company placement
What is printed?
What is printed?
RED = "r"
def f(c):
match c:
case RED:
return "red:" + RED
print(f("g"), RED)- A. None r
- B. red:r r
- C. red:g r
- D. red:g g
Correct answer: C. red:g r
A bare name in a case pattern is a capture pattern, not a comparison with the constant: it always matches and binds the subject to a new local RED inside f. The global RED is untouched. (Use a dotted name such as Color.RED to compare.)
More Python Programming questions
- What is printed? python data = [3, 8, 2, 9, 4] if (n := len(data)) > 4: print(n, end=" ") print([y for x in data if (y := x 2) > 10], y)
- What is printed? python a = [5, 3, 5, 1] a.remove(5) a.insert(10, 7) a.insert(-10, 0) print(a, a.index(5), a.pop(1))
- What is printed? python a = [1, 2, 3, 4] b = a a = a.extend([5]) or a print(a is b, b[-1], [].extend([1]))
- 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:])