Python: If-Else Statement


It is a conditional statement used for selection between two set of statements based on the evaluation of test condition. The statements inside the if block are executed only if the evaluated condition is true. Otherwise statements inside the else block are executed. As we have two set of statements to select based on the test condition, it is also called as Two-way selection statement.

Below is the syntax of if-else statement:

Python if-else statement

Example

	a=-10
	if(a>0):
		print("positive integer")
	else:
		print("Not a positive integer")

Output

Not a positive integer

In the if statement will evaluate condition and result as false then it will jump to else block then it will execute statement of else block.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s