About 53 results
Open links in new tab
  1. How to use multiple cases in Match (switch in other languages) cases in ...

    Oct 20, 2021 · I am trying to use multiple cases in a function similar to the one shown below so that I can be able to execute multiple cases using match cases in python 3.10 def sayHi(name): match name: ...

  2. What is the Python equivalent for a case/switch statement?

    Jul 14, 2012 · Python 3.10.0 provides an official syntactic equivalent, making the submitted answers not the optimal solutions anymore! In this SO post I try to cover everything you might want to know about …

  3. python - Match case statement with multiple 'or' conditions in each ...

    Dec 2, 2022 · Is there a way to assess whether a case statement variable is inside a particular list? We have three lists: a = [1, 2, 3] b = [4, 5, 6] c = [7, 8, 9] Then I want to check whether x is in each list.

  4. Python: match/case by type of value - Stack Overflow

    May 18, 2022 · I came across a weird issue while using the new match/case syntax in Python3.10. The following example seems like it should work, but throws an error: values = [ 1, "hello", T...

  5. How to do an else (default) in match-case? - Stack Overflow

    Aug 16, 2021 · Python recently has released match-case in version 3.10. The question is how can we do a default case in Python? I can do if/elif but don't know how to do else. Below is the code: x = …

  6. python - Continue to match next case after match? - Stack Overflow

    Feb 28, 2023 · According to the official Python documentation (PEP 636), once the first matching pattern is found, the body of that case is executed, and all further cases are ignored. Therefore, C-style fall …

  7. python - How to use match case with a class type - Stack Overflow

    Mar 11, 2022 · I want to use match to determine an action to perform based on a class type. I cannot seem to figure out how to do it. I know their are other ways of achieving this, I would just like to know …

  8. Why doesn't Python have switch-case? (Update: match-case syntax was ...

    Oct 12, 2017 · New match-case syntax, which goes far beyond the capabilities of the traditional switch-case syntax, was added to Python in version 3.10. See these PEP documents:

  9. How do if statements differ from match/case statments in Python ...

    Jun 13, 2021 · 26 This question asks for a switch/case or match/case equivalent in Python. It seems since Python 3.10 we can now use match/case statement. I cannot see and understand the …

  10. python - How to use values stored in variables as case patterns ...

    Python's match is much more than a simple switch statement. If you use bare what you consider "variable names", they are actually going to be Capture Patterns. Besides the fact that you should …