Time for action – comparing objects
Suppose you need to compare two tuples. We can use the assert_equal()
function to do that.
Call the assert_equal()
function:
print("Equal?", np.testing.assert_equal((1, 2), (1, 3)))
The call raises an error because the items are not equal:
Equal? Traceback (most recent call last): ... raise AssertionError(msg) AssertionError: Items are not equal: item=1 ACTUAL: 2 DESIRED: 3
What just happened?
We compared two tuples with the assert_equal()
function—an exception was raised because the tuples were not equal to each other.