Pythonic Switch statement

0 votes
How to create a switch statement in python?
Jun 13, 2018 in Python by yenk434
19 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

You can implement it using dictionaries 

def numbers_to_strings(argument):

    switcher = {
        0: "zero",
        1: "one",
        2: "two",
    }
return switcher.get(argument, "nothing") #"nothing" is the default case
answered Jun 20, 2018 by Nietzsche's daemon
• 4,260 points

Related Questions In Python

0 votes
1 answer

Replacements for switch statement in Python?

You could use a dictionary: def f(x): ...READ MORE

answered May 29, 2018 in Python by ariaholic
• 7,320 points
15 views
0 votes
1 answer

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

if x == 'a':  # Do the ...READ MORE

answered Jul 26, 2018 in Python by Priyaj
• 56,120 points
46 views
0 votes
1 answer

Replacements for switch statement in Python?

If you'd like defaults you could use ...READ MORE

answered Aug 10, 2018 in Python by Priyaj
• 56,120 points
14 views
0 votes
2 answers

Unable to use print statement in python3

print will work when you use print("Your ...READ MORE

answered Feb 14 in Python by Shashank
• 1,350 points
18 views
0 votes
2 answers

how to use print statement in python3?

The print statement has been replaced with a print() ...READ MORE

answered Jul 16, 2018 in Python by Mrunal
• 680 points
22 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
20 views
+4 votes
6 answers
0 votes
1 answer

Python Switch construct?

You can use the python dictionary for ...READ MORE

answered Apr 19, 2018 in Python by Nietzsche's daemon
• 4,260 points
23 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.