elif statement.else statement.if condition:
# do thing1
elif condition2:
# do thing2
else:
# do thing3
For example
a = 50
b = 35
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")
else:
print("a is greater than b")
We can create boolean expressions using relational operators:
and operator takes two arguments, and evaluates as True if both of its arguments are True. Otherwise, it evaluates to False.or operator also takes two arguments. It evaluates to True if either (or both) of its arguments are True, and False if both arguments are False.We can use try and except statements to check for possible errors that a user might encounter.
try:
# some statement
except ErrorName:
# some statement
finally:
print("The 'try except' is finished")
Explanation
First, the statement under try will be executed. If there’s an error such as NameError or a ValueError, and try statement will terminate and the except statement will execute.
def divides(a,b):
try:
result = a / b
print (result)
except ZeroDivisionError:
print ("Can't divide by zero!")