Python | Conditional Statements | if-else statement

The if-else statement is executed when a condition is met, otherwise it does something else (whatever is in the else statement).

The syntax for if-else statement look like the following:

if [condition is true]:
	do something
	do something else

Now, if we take the last example and modify it we would get something like below.

option_one = input('Type number 5 here: ')
if option_one == 5:
	print('number 5 is your option')
	print('you have no options')

If the user types the number 5 at the input then the message printed on the screen will be “number 5 is your option”. If the user types other number than 5 then the message “ you have no options” will be printed on the screen.

Python if-else statement

Leave a Reply