0% found this document useful (0 votes)
27 views3 pages

Python Match Statement MCQs

The document contains multiple-choice questions (MCQs) regarding the Python match statement, introduced in Python 3.10, focusing on its syntax, functionality, and behavior. Key topics include the default case, pattern matching, and the types of data that can be matched. The document serves as a quiz to test knowledge on the match statement and its applications in Python programming.

Uploaded by

Pankaj Navale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views3 pages

Python Match Statement MCQs

The document contains multiple-choice questions (MCQs) regarding the Python match statement, introduced in Python 3.10, focusing on its syntax, functionality, and behavior. Key topics include the default case, pattern matching, and the types of data that can be matched. The document serves as a quiz to test knowledge on the match statement and its applications in Python programming.

Uploaded by

Pankaj Navale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Python Match Statement - MCQs

Q1. What version of Python introduced the match statement?

A) Python 3.8 B) Python 3.9 C) Python 3.10 D) Python 3.6

Q2. What is the default case in a match statement?

A) case default: B) case _: C) case else: D) case None:

Q3. What is the purpose of the match statement?

A) Looping through items B) Handling errors C) Pattern matching D) String formatting

Q4. What will the following code print?

x=2

match x:

case 1: print('One')

case 2: print('Two')

case _: print('Other')

A) One B) Two C) Other D) Error

Q5. What is the role of case _: in a match block?

A) To stop the program B) To define the first case C) To handle unmatched cases (default) D) To

match strings

Q6. Can match be used with a list?

x = [1, 2, 3]

match x:

case [1, 2, 3]: print('List matched')

A) No B) Yes C) Only with tuples D) Only with strings

Q7. What is the output of this code?

val = 'a'

match val:

Page 1
Python Match Statement - MCQs

case 'a' | 'e' | 'i' | 'o' | 'u': print('Vowel')

case _: print('Consonant')

A) Vowel B) Consonant C) Error D) Nothing

Q8. Which statement is TRUE about match?

A) It replaces if-else completely B) It supports structural pattern matching C) It works only with

integers D) It cannot use variables

Q9. What keyword is used inside case to add conditions?

A) then B) elif C) if D) when

Q10. Which of the following data types can be used in match?

A) int B) str C) list D) All of the above

Q11. What happens if multiple cases match the value?

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

Q13. What does this print?

name = 'Bob'

match name:

case 'Alice': print('Hi Alice')

case 'Bob': print('Hi Bob')

case _: print('Hi Stranger')

A) Hi Alice B) Hi Bob C) Hi Stranger D) Error

Q14. match is conceptually similar to which structure in other languages?

A) for loop B) while loop C) switch-case D) try-except

Q15. In a match-case, what happens when no pattern matches and no case _: is defined?

Page 2
Python Match Statement - MCQs

A) Code breaks B) An error occurs C) Nothing happens D) A warning is shown

Q16. What is the output of:

match 5:

case 1: print('One')

case 2 | 3: print('Two or Three')

case _: print('Other')

A) One B) Two or Three C) Other D) Error

Q17. What kind of matching does Python's match statement support?

A) Value matching only B) Type matching C) Structural pattern matching D) None

Q18. Can a tuple be matched in a match statement?

A) No B) Yes C) Only if it has 2 elements D) Only with strings

Q19. What will this print?

x=0

match x:

case 0: print('Zero')

case _: print('Non-zero')

A) Zero B) Non-zero C) Error D) Nothing

Q20. Which one is a valid match-case syntax?

A) match x then: B) switch(x): C) match x: D) if match x:

Page 3

You might also like