pythonfunctionrepr

In Python, what does '<function at ...>' mean?


What does <function at 'somewhere'> mean? Example:

>>> def main():
...     pass
...
>>> main
<function main at 0x7f95cf42f320>

And maybe there is a way to somehow access it using 0x7f95cf42f320?


Solution

  • You are looking at the default representation of a function object. It provides you with a name and a unique id, which in CPython happens to be a memory address.

    You cannot access it using the address; the memory address is only used to help you distinguish between function objects.

    In other words, if you have two function objects which were originally named main, you can still see that they are different:

    >>> def main(): pass
    ... 
    >>> foo = main
    >>> def main(): pass
    ... 
    >>> foo is main
    False
    >>> foo
    <function main at 0x1004ca500>
    >>> main
    <function main at 0x1005778c0>
    

    Documentation with related info: