__name__ for Python class and Python function

This is my first post in the series of small random learnings.

The attribute __name__ is by default present in every python function. But suprisingly an object of a class doesnt have this attribute unless specifically specified.


class example():
    def classFunction():
        return "test"

obj = example()
print obj.__name__  #This is an error

On the other hand ,

def functionA():
    return "A"
def functionB(params):
    return params.__name__

print functionB(functionA) # prints functionA