Switch Statement in Python
Before Python 3.10, there was no feature for Switch statement in Programming. In Python 3.10, they have included match and case statement to implement Switch Case in Programming. Instead of default: case, we write case _: and there is no need to write break statement after each case.
day = 2
match(day):
case 1:
print("Monday")
case 2:
print("Tuesday")
case 3:
print("Wednesday")
case 4:
print("Thrusday")
case 5:
print("Friday")
case 6:
print("Saturday")
case 7:
print("Sunday")
case _:
print("Not a valid number")
Switch statement in Programming
Switch statement in programming enables the execution of different code blocks based on the value of an expression, providing a structured approach to handle multiple cases efficiently. It enhances code readability and simplifies decision-making processes, making it a valuable tool for managing program flow and facilitating branching logic in software development.
Table of Content
- What is Switch Statement?
- Syntax and Structure of Switch Statement
- Case Statement
- Break Statement
- Default Statement
- Switch Statement in C
- Switch Statement in C++
- Switch Statement in Java
- Switch Statement in Python
- Switch Statement in C#
- Switch Statement in JavaScript
Contact Us