In [1]:
assert True, "This is an assert statement"

In [2]:
num = 2.003

In [3]:
assert num > 2, "value must be > 2"

In [4]:
assert num < 2.001, "value can only be a bit bigger than 2"


---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-4-c87e23167cb5> in <module>()
----> 1 assert num < 2.001, "value can only be a bit bigger than 2"

AssertionError: value can only be a bit bigger than 2

In [8]:
def temp_c_to_k(temp_in_c):
    """Convert temperature form C to K
    """
    temp_in_k = temp_in_c + 273.15
    assert temp_in_k > 0, "Can't be negative"
    return temp_in_k

In [6]:
print(temp_c_to_k(10))


283.15

In [9]:
print(temp_c_to_k(10))


283.15

In [10]:
print(temp_c_to_k(-10000000))


---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-10-610b94ba3b16> in <module>()
----> 1 print(temp_c_to_k(-10000000))

<ipython-input-8-d7b84977661b> in temp_c_to_k(temp_in_c)
      3     """
      4     temp_in_k = temp_in_c + 273.15
----> 5     assert temp_in_k > 0, "Can't be negative"
      6     return temp_in_k

AssertionError: Can't be negative

In [ ]: