Pythonic Switch statement

0 votes
How to create a switch statement in python?
Jun 13, 2018 in Python by yenk434
26 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 ariaholic
• 7,340 points
27 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,520 points
87 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,520 points
25 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
33 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
42 views
+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 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 222 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
33 views