If Else Statement in Python

Hello friends how are you, today in this blog i will teach you what is if else statement, syntax of if else , how if else statement works and many programs using if else in a very simple way. 

Let's start

If else statement

Syntax:

if  condition  :
    body _of_if
else:
    body_of_else
  • It is used to test the condition and gives the output in both situation either condition true or false.
  • If the condition is true body of if will execute otherwise body of else execute.

no=int(input("Enter any number:"))
if no>5:
    print("Number is greater than 5")
else:
    print("Number is less than 5")
/*
Output
Enter any number:7
Number is greater than 5
*/


/*Example 1*/
if 10:
    print("Hello")
else:
    print("Hi")
/*
 ### Output ###
Hello
because 10 is non-zero value
*/
/*Example 2*/
if 0:
    print("Hello")
else:
    print("Hi")
/*
 ### Output ###
Hi
*/
/*Example 3*/
if 'A':
    print("Hello")
else:
    print("Hi")
/*
 ### Output ###
 Hello
 because ASCII value of A is 65
 which is non-zero
*/
no=int(input("Enter any number:"))
if no%2==0:
    print("Number is even")
else:
    print("Number is odd")
/*
Output
Enter any number:15
Number is odd
*/

Request:-If you found this post helpful then let me know by your comment and share it with your friend. 
If you want to ask a question or want to suggest then type your question or suggestion in comment box so that we could do something new for you all. 

If you have not subscribed my website then please subscribe my website. 

Try to learn something new and teach something new to other. Thanks.

Post a Comment

0 Comments