Home >>Python Keywords >Python else Keyword

Python else Keyword

Python else Keyword

Python else keyword is used in conditional statements like if statements, and decides what to do if all the conditions are False. It can also be used in try...except blocks.

Here is an example of Python else keyword:

x = 5
if x > 10:
  print("YES")
else:
  print("NO")

Output:
NO
Example 2:

x = 5
try:
  x > 10
except:
  print("Something went wrong")
else:
  print("The 'Try' code was executed without raising any errors!")

Output:
The 'Try' code was executed without raising any errors!