Can someone explain elif with proper example ?Where it can be used ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can someone explain elif with proper example ?Where it can be used ?

14th Jun 2018, 11:20 AM
sam
sam - avatar
6 Answers
+ 4
https://code.sololearn.com/cYaBuX9e2b1u/?ref=app A simple example of else if statement in Java.Try it you will get the idea.
14th Jun 2018, 11:42 AM
☇☇The Flash☇☇
☇☇The Flash☇☇ - avatar
+ 4
Just try to read the code basic function is same for both.
14th Jun 2018, 11:45 AM
☇☇The Flash☇☇
☇☇The Flash☇☇ - avatar
+ 3
Elif is short for 'else if'. It means it is executed when the above 'if' condition is false, but the following condition is true. Example: age =int(input("What's your age?\n")) if age < 13: print("You're a child") elif age < 60: print("You're an adult") elif age < 100: print("You're old") else: print("You're still alive?") In the example, you can see that the second statement runs only if the first is false (meaning age >= 13), and the third runs only if the secod ifs false, and so on. Hope this helped :)
14th Jun 2018, 11:48 AM
Just A Rather Ridiculously Long Username
+ 1
I dont know java . Can you explain ,in context of python.
14th Jun 2018, 11:43 AM
sam
sam - avatar
+ 1
Hey, thanks man .
14th Jun 2018, 11:50 AM
sam
sam - avatar
0
No problem :)
14th Jun 2018, 12:36 PM
Just A Rather Ridiculously Long Username