Update match_case_statement.md

Added nested patterns
pull/1007/head
SAM 2024-06-04 18:28:39 +05:30 zatwierdzone przez GitHub
rodzic e5c88286d5
commit ffcc45ad98
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
1 zmienionych plików z 27 dodań i 0 usunięć

Wyświetl plik

@ -162,6 +162,33 @@ Invalid
```
### Nested Patterns
The patterns can be nested via various means. It can include the mix of the patterns mentioned earlier or can be symmetrical across. A basic of the nested pattern of a list with Patterns with a Literal and Variable is taken. Classes and Iterables can laso be included.
```python
def get_points(points: list) -> None:
match points:
case []:
print('Empty')
case [x]:
print(f'One point {x}')
case [x, y]:
print(f'Two points {x} and {y}')
case _:
print('More than two points')
```
O/P:
```
>>> get_points([])
Empty
>>> get_points([1])
One point 1
>>> get_points([1, 2])
Two points 1 and 2
>>> get_points([1, 2, 3])
More than two points
```
### Complex Patterns
#### Wildcard