gusa10
gusa10

Reputation: 189

Why does 'raised Error' work, but 'assert' doesn't?

There is a difference when I use assert and raised ValuError, why?

The following code, only stop my script when I use raise ValueError, assert does not work.

assert (len(dictA) != len(dictB)), 'Your have an .... error'

if len(dictA) != len(dictB):
    raise ValueError('Your have an ... error')

Upvotes: 2

Views: 87

Answers (1)

Filipe Aleixo
Filipe Aleixo

Reputation: 4242

You need to use

assert (len(dictA) == len(dictB))

The error is thrown when the condition evaluates to False.

Upvotes: 3

Related Questions