Answers for "structural pattern matching python"

0

structural pattern matching python

# Structural pattern matching allows you to write switch/case statements
# in Python. You need to have Python 3.10 to use this feature.
x = 10
match x:
    case 10:
        print('x = 10') # if x is 10, this will print 10
    case 20:
        print('x = 20') # if x is 20, this will print 20
    case _:
        # The underscore allows you to write a default case if none of the
        # conditions above are true.
        print(f'x = {x}')
Posted by: Guest on October-29-2021

Python Answers by Framework

Browse Popular Code Answers by Language