ELS & ELIF Condition

If, else, and elif statements are multi-way decisions that our software makes in response to certain conditions in our code. Few viewers are likely to be unfamiliar with the phrase “elif,” and it differs from the majority of other words, such list or loops, etc., that have the same meaning in both Python programming and the English language. In reality, the word “elif” signifies honest in English. But you must be familiar with the “else-if” statement if you have ever programmed in any language; “elif” is the same thing.

We are now moving closer to a description that is more official. For our program, “if” and “else” are known as decision-making statements. They closely resemble the decisions we make in our daily lives that are based on certain circumstances. I won’t waste your time on the common example because the tutorial covers it in great detail. I would now like to concentrate on more specific technical information.

If the condition is true, the compiler will run the code in the “if” part of the program and exclude the large chunk of code contained in “elif” and “otherwise,” which will not be executed. The compiler, however, will advance to the elif section and continue to execute the code until it finds a true statement if the “if” condition is false (there could be multiple elif statements). If not, the program will run the code in the “otherwise” section if it contains any.

Without a “if,” we cannot apply “otherwise” or “else-if” statements, hence a “if” statement is required. However, if we just need to check between two conditions, we can simply use “if and else,” and even if we only need the code to execute when the statement returns true and to do nothing if it returns false, an else statement is not necessary at all.

difficulties pertaining to how decision statements function

The number of conditions that we could include in our software has no upper bound. There is no limit to the number of elif statements we can employ, however there is only room for one “else” and one “if” statement.

The use of nested if statements, or one if statement inside another if statement, is possible. In many situations, it is really beneficial.

The following logical conditions can be used to create decision statements: Equal to Not equal to Less than Greater than Greater than equal to Less than equal to

Bonus section

As we all know, a “if” statement is required in order to have a “else” or “else-if,” but let’s say you have a lot of code and for some reason need to eliminate the “if” portion of the code (because perhaps your code is better without it), but you do not want to perform a lot of coding again. If so, the solution is as simple as using pass rather than code; this will ensure that your code runs without errors even if the if part is not executed.

Shubhajna Rai
Shubhajna Rai

A Civil Engineering Graduate interested to share valuable information with the aspirants.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in