What problem can occur when retriggering a value without having a variable to receive (Python)?

0

If I have a function that returns a value or True and False, but does not have a variable to receive, can this cause some problem in the code operation?

Example:

def Retorna():
    return False

def Retorna2():
    return 100

Retorna()
Retorna2()
    
asked by anonymous 22.01.2018 / 13:26

1 answer

1

No problem at all.

Although it is not a typical Python language design, where it is common to have functions without a return value, it is possible for a function to always return the object it acted on - use of this returned value is optional.

In Javascript and in some Python libraries it is common to always return the object on which the function acted - that way you can chain other direct calls into the return value. But if you do not have other calls, nothing happens.

There is not even an extra memory expense - if there is no variable to store a return value: as soon as it is returned, as it has no reference to it, it is destroyed, and its memory released. >     

22.01.2018 / 14:45