match case

Published by onesixx on

Python구조적-패턴-매칭-파이썬에서-switchcase문

https://youtu.be/2yHZSPZdh-o

status = 200

# if status == 200:
#     print("OK!")
# elif status == 300:
#     print("Err")
# else:
#     print("unknown")

# switch py=3.10
match status:
    case 200:
        print("OK!")
    case 300 | 400:
        print("Err")
    case _:
        print("unknown")

switch case와 달리, 패턴 매칭

def draw(point)
\tmatch point:
        case(x, y):
            print(f'x:{x}, y:{y}')
        case(x, y, z):
            print(f'x:{x}, y:{y}, z:{z}')
            
draw(10,20,30)
draw(10,20)
...

Categories: Python Basic

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x