World's Best AI Learning Platform with profoundly Demanding Certification Programs
Designed by IITians, only for AI Learners.
Internship Partner

In Association with
In collaboration with



Designed by IITians, only for AI Learners.
Internship Partner
In Association with
In collaboration with
New to InsideAIML? Create an account
Employer? Create an account
Designed by IITians, only for AI Learners.
Internship Partner
In Association with
In collaboration with
Enter your email below and we will send a message to reset your password
Designed by IITians, only for AI Learners.
Internship Partner
In Association with
In collaboration with
By providing your contact details, you agree to our Terms of Use & Privacy Policy.
Already have an account? Sign In
Designed by IITians, only for AI Learners.
Internship Partner
In Association with
In collaboration with
By providing your contact details, you agree to our Terms of Use & Privacy Policy.
Already have an account? Sign In
Download our e-book of Introduction To Python
4.5 (1,292 Ratings)
589 Learners
Pallavi Dhotre
2 years ago
switch(Boolean expression) {
case 1:
// code block1
break;
case 2:
// code block2
break;
default:
// code block
}
#python switch case example using dictionary value string
def language(i):
switch_demo = {
0: 'Python',
1: 'Java',
2: 'C++',
3: 'Ruby',
4: 'C'
}
print( switch_demo.get(i, "Invalid language"))
inp=int(input("Enter your choice: "))
language(inp)
Enter your choice: 0
Python
#python switch case example using dictionary
def Python():
print("I like Python")
def Java():
print("I like Java")
def CPP():
print("I like CPP")
def Ruby():
print("I like Ruby")
def C():
print("I like C")
def language(i):
switch_demo = {
0: Python,
1: Java,
2: CPP,
3: Ruby,
4: C
}
obj=switch_demo.get(i, lambda :"Invalid language")()
return (obj)
i=int(input("Enter your choice: "))
language(i)
Enter your choice: 3
I like Ruby