Here are four simple invocations of assert:
>>> assert 1==2
Traceback (most recent call last):
File \"\", line 1, in ?
AssertionError
&g
The last assert
would have given you a warning (SyntaxWarning: assertion is always true, perhaps remove parentheses?
) if you ran it through a full interpreter, not through IDLE. Because assert
is a keyword and not a function, you are actually passing in a tuple as the first argument and leaving off the second argument.
Recall that non-empty tuples evaluate to True
, and since the assertion message is optional, you've essentially called assert True
when you wrote assert(1==2, "hi")
.