If statement in python is simple as in english. Syntax is as below
1 2 3 4 5 6 if case1: perform action1 elif case2: perform action2 else: perform action3
⚠️ Indention is important. Ensure to indent on next line of if , elif and else
1 2 3 4 5 6 7 8 9 10 >>> lang = 'Python' >>> if lang == 'Java': print('Welcome to the Java!') elif lang == '.Net': print('Welcome to the .Net class!') elif lang == 'Class' or loc == 'Python': print('Welcome to the Class!') print('This is the second print') else: print('Which class you are in?')
In above the logic works from top to bottom and exits once first condition satisfied and commands are executed.
Else will be default action if no other case matched.
Thanks for reading till end.
Followus on insta @techpechu
Join Our Discord
We do run a youtube channel in Indian regional language Tamil called TechPechu. Do subscribe us for moral support. Happy Learning.