Python else Keyword
Print "YES" if x larger than 3, otherwise print "NO":
if x > 3:
Definition and Usage
else keyword is used in conditional
statements (if statements), and decides what to do if the condition is
else keyword can also be use in
try...except blocks, see example below.
Use the else keyword in a try...except block to define what to do if no errors were raised:
x > 10
print("Something went wrong")
print("The 'Try' code was executed without raising any errors!")
Read more about conditional statements in our Python Conditions Tutorial.