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)
  1. A. None r
  2. B. red:r r
  3. C. red:g r
  4. 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

Exams that ask this topic