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?

Community
  • 1
  • 1
Neil G
  • 32,138
  • 39
  • 156
  • 257

1 Answers1

4

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.

Andrew Clark
  • 202,379
  • 35
  • 273
  • 306