Python if-else Statements :

Decision Making :

Decision making is anticipation of conditions occurring while execution of the program and specifying actions taken according to the conditions. Decision structures evaluate multiple expressions which produce TRUE or FALSE as outcome. You need to determine which action to take and which statements to execute if outcome is TRUE or FALSE otherwise. Python programming language provides following types of decision making statements :

  1. if statements
  2. if-else statements
  3. nested if-elif-else statements

if Statement :

An "if statement" is written by using the if keyword.

Syntax :

if expression: statement(s)

Example :

  1. a = 100
  2. b = 100
  3. if(a==b) : print("a or b are equal");
  4. input()

Output :

python if statements

if-else Statement :

The else keyword catches anything which isn't caught by the preceding conditions.

Syntax :

if expression: statement(s)
else: statement(s)

Example :

  1. a = 55
  2. b = 55
  3. if(a < b) : print("a greater than b")
  4. else : print("a and b are equal [else statement]")
  5. input()

Output :

python if_else statements

Next Update


We have a YouTube channel for live game streaming purposes, the channel name is "NightHawk". You can visit our gaming channel and support us, Thank you