11 Réponses
+ 1
Andrés Puello
In python 3.10 match statement was introduced. It act like a switch statement and it is match with the given pattern in case statement.
Here is the documentation,
https://docs.python.org/3.10/whatsnew/3.10.html
+ 4
there is only a kind of switch statement since python 3.10:
https://towardsdatascience.com/pattern-matching-in-python-3-10-6124ff2079f0
+ 2
As stated, until python 3.10 is released with the match-case the closest we have is the use of a dictionary.
https://code.sololearn.com/c9scA7o07x8n/?ref=app
+ 2
Andrés Puello Here's a really crude possibility:
switch = lambda x, y: exec(y[x])
switch(3, {
1: """
print('me')
for i in range(8):
print(88) """,
2: "print('89')",
3: """
def is_digit(num):
ascii = ord(num)
return ascii > 47 and ascii < 58
print(is_digit('8')) """,
"May": "raise ValueError"})
# Hope this helps
+ 2
Use for loop and inside that use if , elif and else statement.
+ 1
Codes for learning purpose.
Hope this helps you.
https://code.sololearn.com/c9xAnCn96Pmt/?ref=app
https://code.sololearn.com/ccJqA9VuQ2yU/?ref=app
https://code.sololearn.com/cLLY0L3DaK6F/?ref=app
+ 1
I've found a article on python documentation, but Idk if that is a possibility.
+ 1
You can use if and while loop instead of switch in python because Python do not have Switch case
0
It doesn’t come predifined in python as with js. Unless you define a function. Otherwise its best you use if-else statement
0
wich article?