Blog
Why there is no switch statement in python? – tccicomputercoaching.com
- March 13, 2020
- Posted by: Riddhi Dhandha
- Category: Python Coaching at TCCI
Switch case is a powerful decision-making construct commonly used in modular programming.
Unlike other programming languages, Python doesn’t provide a switch case instrument over the self.
However, it has many other constructs like a dictionary, lambda function, and classes to write a custom implementation of the Python switch case statement.
One example of Switch in Python :
Here, we define a function week() to tell us which day a certain day of the week is. A switcher is a dictionary that performs this mapping.
As you can see, for values other than the ones we mention in the switcher, it prints out “Invalid day of week”. This is because we tell it to do so using the get() method of a dictionary.
TCCI teach so many Programming Languages to Diploma-Degree Engineering students, School students, BCA, MCA, PGDCA, BSC_IT, and any Non-IT person.
We are at Bopal and Satellite.
Call us @ 8980010210
Visit us @ www.tccicomputercoaching.com