-1

Today I was practicing some return types, and put this code:

def funcion(numero):
   return numero


print(funcion)

And the output is

<function funcion at 0x7fc48554f950>

but the weirdest thing is that each time I try to run the code it appears other output with different digets/numbers at the end, except 0x7fc48554f950 will be 0x7f8658401950 for example.

I was wondering why this happens? The output from python 2.7.x and 3.6.5 are different as well, which would be and awalys with the beginning and ea0.

  • 3
    Note that you're looking at the print of the function object itself, not the return value. (because you never called your function) – Paritosh Singh Jan 15 '20 at 10:06
  • try `print(function())` – Clément Jan 15 '20 at 10:07
  • So, printing the object itself will appear random combinations of words and numbers? – bl4ckch4ins Jan 15 '20 at 10:07
  • What where you expecting to see? If you say "a number", my next question will be: Which number? – tobias_k Jan 15 '20 at 10:07
  • @bl4ckch4ins Not random, but the representation of a function called "funcion" stored at a certain location in memory. – tobias_k Jan 15 '20 at 10:08
  • 1
    it is not random it is the address where the function is pointing (in hexadecimal format) – Clément Jan 15 '20 at 10:09
  • 1
    @Clément ... *should* you happen to use CPython. YMMV in other flavours. – deceze Jan 15 '20 at 10:09
  • @Clément it doesnt appear anything it's just gives a error of syntax – bl4ckch4ins Jan 15 '20 at 10:10
  • @tobias_k I see, how I can understand better about the memory information? to see how it works? – bl4ckch4ins Jan 15 '20 at 10:12
  • 1
    It's an implementation detail you don't need to worry about much. You're looking at how a *function object* is represented when you print it. There's no inherently right or wrong or meaningful way to represent a function object, so just take it as it is and focus on the fact that you're not calling your function instead… – deceze Jan 15 '20 at 10:14
  • Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackoverflow.com/rooms/205996/discussion-on-question-by-bl4ckch4ins-why-i-get-this-return-value). – deceze Jan 15 '20 at 10:24

1 Answers1

0

You are printing information about the function objection instead of calling it. The right way to do so would be

print(funcion())

but you will need to pass a value for numero like

print(funcion(10))
offeltoffel
  • 2,691
  • 2
  • 21
  • 35