Friday, 15 July 2011

How do you assert something is not true in Python? -



How do you assert something is not true in Python? -

in trying understand assert in python, inverting it, came this...

>>> assert != ( 5 > 2 ) >>> assert != ( 2 > 5 )

now first line fails , sec passes. what's idiomatic way assert false?

you'd utilize boolean not operator, not != inequality comparing operator:

>>> assert not (5 > 2) traceback (most recent phone call last): file "<stdin>", line 1, in <module> assertionerror >>> assert not (2 > 5)

an assert passes if test true in boolean sense, need utilize boolean not operator invert test.

python assert

No comments:

Post a Comment