[Python] Cost of exception handlers in Python

Discussão em 'Python' iniciado por Stack, Maio 13, 2025.

  1. Stack

    Stack Membro Participativo

    In another question, the accepted answer suggested replacing a (very cheap) if statement in Python code with a try/except block to improve performance.

    Coding style issues aside, and assuming that the exception is never triggered, how much difference does it make (performance-wise) to have an exception handler, versus not having one, versus having a compare-to-zero if-statement?

    Continue reading...

Compartilhe esta Página