Why Does Your Python Program Return “function at” with a Hexadecimal?

Problem scenario
You run a Python program. A value of a variable is printing "function at" with a hexadecimal. How can the variable be the intended value of the function and not this meta data of the Python interpreter or just-in-time compiler?

Solution
Use "()" at the end of the function invocation. This syntax is necessary. Here is an example that will cause the problem:

def cool():
   a = "foobar"
   return a

q = cool
print(q)

Here is an example that will not cause the problem:

def cool():
   a = "foobar"
   return a

q = cool()
print(q)

Leave a comment

Your email address will not be published. Required fields are marked *