Reading Tests

Reading Tests Lesson - Base Python Track

The assert statement

The assert statement allows us to verify that our code works as expected, in a simple and reliable way. Python interprets assert as we'd do: "make sure this current statement is true". Examples:

assert 2 + 2 == 4  # make sure "two plus two is equals to four"
assert add(2, 3) == 5  # make sure that "if we invoke add with 2 and 3, the result is 5"

This makes it a really powerful statement and a really useful one to verify our code works. We can just write the expected output of our functions with asserts, and then sit to code the actual function.

    Questions: