> On 2 Mar 2021, at 20:54, Marco Sulla <marco.sulla.pyt...@gmail.com> wrote:
> 
> I have a curiosity. Python, as many languages, has assert as a
> keyword. Can't it be implemented as a function? Is there an advantage
> to have it as a keyword?

assert condition, expression

Only is condition is false with expression be evaluated.
So you can safely do expensive things I the expression with incuring and cost 
if the condition is True.

With a function assert the 2nd part would have to evaluated regardless of the 
state of the condition.
Which would slow down the code for no benefit.

Barry

> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to