The output problem of python print function

class Foo(object):
    def f(self):
        pass
        
a=Foo()
print(id(Foo.f),id(a.f))
print(a.f,id(Foo.f),id(a.f))
print(str(a.f),id(Foo.f),id(a.f))

output result:

2005918566192 2005885408456
<bound method Foo.f of <__main__.Foo object at 0x000001D30A108B00>> 2005918566192 2005885410056
<bound method Foo.f of <__main__.Foo object at 0x000001D30A108B00>> 2005918566192 2005885408456

question: why are the three outputs different?
from the result, we can see that the _ _ str__ method of the object is not called by itself during print, so what"s the use of _ _ str__?

Mar.15,2021

it is not clear why the results of the three print are different. It is estimated that A.F occurs automatically in memory.
as to why _ _ str__, is not called because the code does not require a description of a, all that is returned is the description of method f. In the
output, the content after "of" in angle brackets is for the machine, so the _ _ repr__ method of the Foo class is called instead of _ _ str__


Why is Foo.f different from a.f ? To put it simply: Foo.f accepts a parameter, while a.f has been bound to Foo.f , the first parameter is a , so Foo.f and a.f are different. a.f is the version of Foo.f bound to the parameter, and Foo.f = = a.f. binding function _ <

official documents:

When an instance method object is created by retrieving a user-defined function object from a class via one of its instances, its _ self_ attribute is the instance, and the method object is said to be bound. The new method's _ func_ attribute is the original function object.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3c648-2bb58.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3c648-2bb58.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?