Time for action – comparing strings

Let's compare strings. Both strings are the word "NumPy":

  1. Call the assert_string_equal() function to compare a string with itself. This test, of course, should pass:
    print("Pass", np.testing.assert_string_equal("NumPy", "NumPy"))

    The test passes:

    Pass None
    
  2. Call the assert_string_equal() function to compare a string with another string with the same letters, but different casing. This test should throw an exception:
    print("Fail", np.testing.assert_string_equal("NumPy", "Numpy"))

    The test raises an error:

    Fail
    Traceback (most recent call last):
    
        raise AssertionError(msg)
    AssertionError: Differences in strings:
    - NumPy?    ^
    + Numpy?    ^
    

What just happened?

We compared two strings with the assert_string_equal() function. The test threw an exception when the casing did not match.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset