If Else Statement in Python

Hi Guy's , Here is the article if else statement in python programming. An if statement identifies which statement to run based on the value of a Boolean expression.or if else statement check condition first . if condition true then if part of block execute . if condition false then else part of block run.
syntax : -
if (Condition)
{
    then statement;
}
else
{
   else - statement 
}
if statement without an else
syntax : -
if (Condition)
{
    then statement;

}
Example 1 :
Example 1 :
Code Explanation :
n = int (input ('Enter Any Number : ')) : At here " Enter Any Number : " that display into output screen.since here i am using input method so whatever we enter that accept into string and after applying int typecasting that convert into integer and store value into n.
next line if n % 2 == 0: Modulus operator return remainder values suppose user enter 9 then 9%2 that return 1 now check 1 == 0 condition false then else block execute and print 9 Number is Odd.

Example 2:

Example 2 :
Code Explanation
a = 19 , b = 7
if a > 10  if 19 > 10 True then control inside of if block.
now , if b >= 24  7 >= 24 False, else part execute
print A Greater.

Happy Coding ... Thanks.
Previous
Next Post »