Python Match Statement MCQs
Python Match Statement MCQs
x=2
match x:
case 1: print('One')
case 2: print('Two')
case _: print('Other')
A) To stop the program B) To define the first case C) To handle unmatched cases (default) D) To
match strings
x = [1, 2, 3]
match x:
val = 'a'
match val:
Page 1
Python Match Statement - MCQs
case _: print('Consonant')
A) It replaces if-else completely B) It supports structural pattern matching C) It works only with
A) All will execute B) First matching case will execute C) Last one will execute D) Throws error
Q12. How many times does a match block execute for a value?
A) Until all match B) Once for every case C) Only once D) Depends on condition
name = 'Bob'
match name:
Q15. In a match-case, what happens when no pattern matches and no case _: is defined?
Page 2
Python Match Statement - MCQs
match 5:
case 1: print('One')
case _: print('Other')
x=0
match x:
case 0: print('Zero')
case _: print('Non-zero')
Page 3