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

Asked

Viewed 47 times

0

If I have a function that returns a value or True and False, but doesn’t have a variable to receive, this may cause some problem in the functioning of the code?

Example:

def Retorna():
    return False

def Retorna2():
    return 100

Retorna()
Retorna2()
  • 1

    No, the only thing the value returned will be lost in the limb of memory and you won’t be able to access it.

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 that a function always returns the object on which it acted - the use of this returned value is optional.

In Javascript and some Python libraries it is common to always return the object the function has acted on - this way you can chain other direct calls to the return value. But if you don’t have any other calls, nothing happens.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.