Pythonic Switch statement

0 votes
How to create a switch statement in python?
Jun 13, 2018 in Python by yenk434
221 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
202 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,080 points
515 views
0 votes
2 answers

Replacements for switch statement in Python?

The recommended path for Python 3.10 which ...READ MORE

answered Feb 9 in Python by Soham
• 9,330 points
202 views
0 votes
0 answers

Replacements for switch statement in Python?

I want to write a function in ...READ MORE

Apr 22 in Python by Edureka
• 11,040 points
41 views
0 votes
0 answers

Replacements for switch statement in Python?

I want to create a Python function ...READ MORE

Sep 21 in Python by Samuel
• 360 points
19 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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 3,020 views
0 votes
1 answer
+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,790 points
2,221 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
171 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP