Ad
  • Custom User Avatar

    No, your if statement is more efficient. The max function spends a few more CPU cycles: https://github.com/python/cpython/blob/main/Python/bltinmodule.c#L1681

    Nonetheless, I prefer the solution using 'max' because of readability.
    That's because for the vast majority of lines of Python, you'll never notice the difference between them taking 10 operations or 100 operations, as CPUs are really fast. But if the next coder has a hard time reading what you wrote, then that will hold back the whole project.

    In the rare cases where performance matters (i.e. in the most inner loop of the most runtime intense section of the program), I would care about performance. But then I wouldn't necessarily write that part in Python.