JOIN OUR FORUM
What are assertions in Python?
An assertion is a sanity check that you can turn on or turn off when you are done with your testing of the program.
The easiest way to think of an assertion is to liken it to a raise-if statement (or to be more accurate a raise-if-not statement). An expression is tested, and if the result comes up false, an exception is raised.
assert Expression[, Arguments]
def KelvinToFahrenheit(Temperature): assert (Temperature >= 0),"Colder than absolute zero!" return ((Temperature-273)*1.8)+32 print KelvinToFahrenheit(273) print int(KelvinToFahrenheit(505.78)) print KelvinToFahrenheit(-5) When the above code is executed, it