Repository navigation
Module 06 TODO 3: what's the idiomatic match-case for 'editor' or 'author'? #17
Answered
by
mgkvibez
dab00gieman
asked this question in
Q&A
|
# Write a match-case statement for the variable 'role' below:
# - If role is "admin", print "Full access"
# - If role is "editor" or "author", print "Write access"For the combined branch, is |
Answered by
mgkvibez
Oct 27, 2026
Replies: 1 comment
|
Yes — the OR-pattern is the idiomatic form: match role:
case "admin":
print("Full access")
case "editor" | "author":
print("Write access")
case "guest":
print("Read access")
case _:
print("No access")Two things worth pinning while you're learning
The wildcard |
0 replies
Answer selected by
dab00gieman
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes — the OR-pattern is the idiomatic form:
Two things worth pinning while you're learning
match:case "editor" | "author":is an OR-pattern — matches if any alternative matches. This is the construct you reach for by default.case ("editor", "author"):— parentheses without|form a tuple literal pattern, which matches an actual 2-tuple whose elements are those strings — i.e., it matches("editor", "author"), never the string"editor". It fails silently in tests (…