How can we type return True or return False into the code? Can you please show an example?
return to exit from a function with a certain value:
def add_numbers(): print(1 + 1) return(2 + 2) # the function exits here print(3 + 3) # this line never gets run, the function stops at `return` add_numbers() # result: 4
It’s the same if you’re working with booleans:
def is_big_number(n): if n > 100: return(True) # if the condition matches, the function exits here print("The number is bigger than 100") # not run else: return(False) # if the first condition didn't match, the function exits here print("Number is smaller than 100") # not run is_big_number(58) # result: False