Returning an object which will only be used sometimes Returning an object which will only be used sometimes selenium selenium

Returning an object which will only be used sometimes


You actually return a reference to the object, meaning that, if it is not used, it will be garbage collected (deleted from memory).

It causes no significant problems in terms of performance.

In term of best practices, you should name your function appropriately to indicate that it returns something pop_by_name would probably be better (pop means delete and return).