Start To Learn Python Right Now EP10: Using IF, ELIF and ELSE with Python

 

In the previous post, we learned about Python Loops. Now, we are going to learn about Python IF and ELSE usage. IF and ELSE is the basic function model in every Programming language. This is a commonly used method in both professional and beginner-level programs. Let's learn What is IF, first.


What is IF...

  IF statement is used to perform on a task when the value you entered finds the requirements you have entered. It is working like an automation system in basic. You can set a requirement inside an IF condition and execute a value you want. Then the IF statement finds the requirements inside the value and returns true or false according to the result. This is how IF working real-time,
   a = "softexs.com"
    if  a == softexs.com:
            print(a)

   You can use a Python Operator or Gate to compare requirements and values. 

Also, Python IF conditions is supporting to any data types like strings, integers, floats, and many more.

What is ELIF

   ELIF is the second stage of building a conditional modal. but this is rarely using the function because you guys can use another statement instead of this. This model performs after the main IF function and you are able to put any number of ELIF functions in one conditional model. This is mostly like the IF condition. It also enables you to put a specific requirement that value needs to execute. Now, let's see how it's working
  a = "softexs.com"
  if a == "softexs":
        print(a)
  elif a == "softexs.com":
            print(a)


What is ELSE...

  ELSE is the last statement of the Python Conditional model. It is using to execute a final task if all other statements are false.  In simply ELSE means if this wasn't happened what happend next. This else doesn't contain any parameter I mean requirement or value inside it. It is just executing the final task without accepting any other thing. Another thing you need to know is we can't call ELSE without the IF. 

a = "softexs"
if a == "softexs.com":
  print(a)
else:
  print("softexs.com")



Post a Comment

If you have any doubt, Let us know

Previous Post Next Post