MemotivaPattern matching

What is a guard clause in pattern matching?

Pattern matching

Audio flashcard · 0:12

Nortren·

What is a guard clause in pattern matching?

0:12

A guard is an extra condition added to a case using if. The case matches only if both the pattern matches and the guard is true. Guards are useful when a structural pattern matches the shape but additional conditions on the values are needed.
peps.python.org