Python Programming For Beginners - Learn Python Programming in 24 Hours by Learning UpSkill

Python Programming For Beginners - Learn Python Programming in 24 Hours by Learning UpSkill
Author: Learning, UpSkill [Learning, UpSkill]
Language: eng
Format: epub
Publisher: UNKNOWN
Published: 2016-10-10

IF ELSE STATEMENT:

Like other languages in Python too we can combine else statement with if statement. An else statement contains the block of code that executes if the conditional expression in if statement resolves to 0 or a false value.

The else statement is an optional statement and there could be at most only one else statement following if .

Syntax:

if (expression):

statement(s)

else:

statement(s)

Let’s move to an example: Get an input from a user and check whether it is even or odd.

A = int(input(“Enter the number”))

if A %2==0:

print “The number is even”

else:

print “The number is odd”