Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

If statement in python example program

Decision Making In Python (IF):


  • As we lead our life we have to take decisions. Similarly, as we make progress in programming and try to implement complicated logics, our program has to take decisions. But how? Well the answer is below
  • if statement
  • If statement is the most simple decision making statement. It is used to decide whether a certain statement or block of statements will be executed or not i.e if a certain condition is true then a block of statement is executed otherwise not.


 If condition:
Statement 1
Statement 2
Statement 3
………………..
…………………
………………..
Statement n

  • Here the condition is evaluated in terms of boolean values i.e. either the evaluation of condition results 1 or 0 i.e.. True(1) or False(0) 
  • If the condition evaluates to True(1) then the block of statements below the if statement gets executed 



#1: Python example program to illustrate if statement

  1. #Python program to illustrate if statement
  2. a=21
  3. If a
  4. print(“if-1 statement is executed successfully”)
  5. If a>18:
  6. print(“if-2 statement is executed successfully”)

  7. Output:
  8. if-2 statement is executed successfully

Output:
  1. if-2 statement is executed successfully




This post first appeared on Java Tutorial - InstanceOfJava, please read the originial post: here

Share the post

If statement in python example program

×

Subscribe to Java Tutorial - Instanceofjava

Get updates delivered right to your inbox!

Thank you for your subscription

×