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

0 votes
I am new to python and i was trying to figure out as what are the things I can use for using a Switch case in python?
Jul 26, 2018 in Python by bug_seeker
• 14,970 points
47 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

if x == 'a':

 # Do the thing

elif x == 'b':

 # Do the other thing

if x in 'bc':

 # Fall-through by not using elif, but now the default case includes case 'a'!

elif x in 'xyz':

 # Do yet another thing

else:

 # Do the default

answered Jul 26, 2018 by Priyaj
• 56,120 points

Related Questions In Python

+1 vote
1 answer

What is the correct order to learn concepts in Python for machine learning?

Machine Learning is a vast domain. It ...READ MORE

answered Jul 25, 2018 in Python by ANMOL
• 3,620 points
30 views
0 votes
1 answer

What is the meaning of “int(a[::-1])” in Python?

Assumming a is a string. The Slice ...READ MORE

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

What is the python keyword “with” used for?

Please visit this site to know abt ...READ MORE

answered Aug 31, 2018 in Python by Somesh
26 views
0 votes
1 answer

What is equivalent for 'foreach' in Python

Its also interesting to observe this To iterate ...READ MORE

answered Oct 17, 2018 in Python by findingbugs
• 4,730 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
23 views
0 votes
1 answer

What is the flow control for “continue” in python?

This is the way "continue" statement works! You ...READ MORE

answered Jul 16, 2018 in Python by Priyaj
• 56,120 points
30 views
+1 vote
1 answer

What is the function for Factorial in Python

Easiest way: math.factorial(x) (available in 2.6 and ...READ MORE

answered Aug 21, 2018 in Python by Priyaj
• 56,120 points

edited Aug 21, 2018 by Omkar 56 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.