How can you implement a switch-case statement in Python? In this video you will find the answer!
----------------------------------------------------------------------------------------------------------------
💻 Code (Version 1) 💻
def switch(value):
return {
"one" : 1,
"two" : 2,
"three" : 3,
"four" : 4,
"five" : 5
}.get(value, 42)
print(switch("three")) # Prints "3".
-----------------------------------------------------------------------------------------------------------
💻 Code (Version 2) 💻
dict = {
"one" : 1,
"two" : 2,
"three" : 3,
"four" : 4,
"five" : 5
}
def switch(value):
return dict.get(value, 42)
print(switch("three")) # Prints "3".
-----------------------------------------------------------------------------------------------------------
On this page of the site you can watch the video online Switch-Case Statement in Python with a duration of hours minute second in good quality, which was uploaded by the user pwnoverflo 23 April 2019, share the link with friends and acquaintances, this video has already been watched 32,482 times on youtube and it was liked by 327 viewers. Enjoy your viewing!