2

Possible Duplicate:
design of python: why is assert a statement and not a function?

In Python 3, print was made into a function. What are the benefits of having assert be a statement?

4
  • well, it's not supposed to return anything, maybe that's why Commented Dec 11, 2012 at 22:14
  • print is not supposed to return anything either :) Commented Dec 11, 2012 at 22:15
  • @MikeCorcoran -- I was just about to point that out. :) Commented Dec 11, 2012 at 22:17
  • Oops, sorry both. Voted to close. Commented Dec 11, 2012 at 22:17

1 Answer 1

3

For optimization. If you run your Python script with the -O option no code will be generated for assert statements. This would not be possible if assert were a function.

See the documentation on assert, which references this behavior.

Sign up to request clarification or add additional context in comments.

1 Comment

+1. I wonder whether pypy be able to optimize away empty functions one day…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.