Learn python assert statement by examples

Description:

Assert statements are a convenient way to insert debugging assertions into a program.
You can use it by :
assert <condition>

assert <condition>,<error message>
When condition is False, python application will raise an exception, error message will be displayed, True and application will continue.

Examples:

1.Make sure inputs and targets array dimensions are the same.

def iterate_minibatches(inputs, targets, batchsize, shuffle=False):

    assert len(inputs) == len(targets),"inputs and target is not the same"

    ......

Leave a Reply

Your email address will not be published. Required fields are marked *