ExampleEdit & Run
#Use the hasattr() Function

print(hasattr(list, 'sort'))
print(hasattr("pynerds", "capitalize"))

print(hasattr((1, 2), 'sort'))
Output:
True True False [Finished in 0.026701341000000767s]

The hasattr() function checks whether an object has an attribute with the given name. An attribute can be a  variable, method, property, data member, etc.

Syntax:
hasattr(obj, attr)
obj The object of which the attribute has to be checked
attr A string specifying the name of the the attribute whose presence has to be tested in obj.

The function returns True if the object contains the specified attribute name, otherwise False.

ExampleEdit & Run
print( hasattr(str, 'join') )
print( hasattr(str, 'lower') )
print( hasattr(str, 'isalpha') )
print( hasattr(str, 'sort') )

L = [] #list
print( hasattr(L, 'sort') )
print( hasattr(L, '__len__') )
print( hasattr(L, 'append') )

S = set() #set
print( hasattr(S, 'add') )
print( hasattr(S, 'update') )
Output:
True True True False True True True True True [Finished in 0.012805540000000448s]

Example with user defined object

ExampleEdit & Run
class Demo:
    x = 10 
    def demofunc():
        pass

print(hasattr(Demo, 'x'))
print(hasattr(Demo, 'demofunc'))
print(hasattr(Demo, 'y'))
Output:
True True False [Finished in 0.012730180000000146s]