linda.s wrote:
> Python manual has a very brief introduction of "assert" statements. It
> is very difficult for me to understand it. Can anyone give me an
> example?
>
#example of assert.py
def test(a):
if 25 / 4 == a:
return True
else:
return False
def assert_it(a):
try:
assert a
print "Success!"
except AssertionError:
print "something went wrong!"
f = test(4)
assert_it(f)
f = test(6)
assert_it(f)
#--- end code
It seems to me that you don't really need to know what assert is,
because the value of __debug__ will probably be true,
and so you might as well write if not a: raise AssertionError
instead, except I guess assert is shorter.
But then if you use assert assuming __debug__ will be true,
then if it's not bad things will happen.
I'm sure someone can give you a better explanation of this,
but I have to get to class.
HTH,
-Luke
> Thanks,
> Linda
> _______________________________________________
> Tutor maillist - [email protected]
> http://mail.python.org/mailman/listinfo/tutor
>
>
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor