News for hackers. Stuff that matters.
Re:What’s inside Python ‘for’ loop? by muthuraj57 on Tuesday March 26, 2019 @02:08AM (#19489606)
I'm not familiar with Python since I'm from Java background. In Java throwing exceptions is costly (like null check is preferred over catching NPE) since exception needs to get stacktrace which involves quite a lot of reflection.

Is this the case with python too? or throwing exception is "free" here?

Re:What’s inside Python ‘for’ loop? by uranusjr on Tuesday March 26, 2019 @03:27PM (#19495210)
Sort of. In Python the stacktrace is always built for every step you take in code, so exceptions are not particularly costly compared to other operations. Reflection is also not relatively more costly since types are objects just like everything else.

It could even be more efficient than return value checking in certain cases.