File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -21,9 +21,19 @@ def main():
21
21
result = "x is less than y" if (x < y ) else "x is greater than or equal to y"
22
22
print (result )
23
23
24
- # Python does not have support for higher-order conditionals
25
- # like "switch-case" in other languages
26
-
24
+ # new in Python 3.10
25
+ # the match-case construct can be used for multiple comparisons
26
+ value = "one"
27
+ match value :
28
+ case "one" :
29
+ result = 1
30
+ case "two" :
31
+ result = 2
32
+ case "three" | "four" :
33
+ result = (3 , 4 )
34
+ case _:
35
+ result = - 1
36
+ print (result )
27
37
28
38
if __name__ == "__main__" :
29
39
main ()
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ def main():
12
12
13
13
# conditional statements let you use "a if C else b"
14
14
15
+ # match-case makes it easy to compare multiple values
16
+
15
17
16
18
if __name__ == "__main__" :
17
19
main ()
You can’t perform that action at this time.
0 commit comments