Pythonic Switch statement

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

1 answer to this question.

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 aryya
• 7,440 points
118 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
• 58,120 points
398 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
• 58,120 points
97 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, 2019 in Python by Shashank
• 1,370 points
253 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
336 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,160 views
0 votes
0 answers
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,810 points
1,627 views
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
113 views