Assert statements in python 3.1

G

genxtech

This is more of a curiosity question then anything else... I was just
wondering why in version 3 of python assertions weren't converted to
use parenthesis, since print was.

I am just asking because it seems the following line of code would
seem more readable as a function:
assert 2 + 2 == 5, "Only for very large values of 2."
 
M

Mark Dickinson

This is more of a curiosity question then anything else...  I was just
wondering why in version 3 of python assertions weren't converted to
use parenthesis, since print was.

I am just asking because it seems the following line of code would
seem more readable as a function:
   assert 2 + 2 == 5, "Only for very large values of 2."

Well, part of the idea of asserts is that when you're running with
optimizations turned on (python -O), asserts should be disabled. But
if assert were a normal function then in

assert(expensive_check)

the argument expensive_check would be evaluated both with 'python' and
with 'python -O'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,135
Latest member
VeronaShap
Top