Total Pageviews

Saturday, April 18, 2020

SWITCH CASE IN PYTHON

Python does NOT have a built-in switch-case statement like C/C++ or Java.

But we can simulate switch-case using:

  • if-elif-else
  • dictionary mapping (best method)

🎯 What is Switch Case?

A switch-case is a selection control structure used to execute one block of code among many alternatives based on a value.


📌 Example Idea

If choice = 1 → Add
If choice = 2 → Subtract
If choice = 3 → Multiply

No comments:

Post a Comment