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.