ExampleEdit & Run
#Use the hasattr() Function

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

print(hasattr((1, 2), 'sort'))
Output:
TrueTrueFalse[Finished in 0.010488733882084489s]

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.
Parameters:

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:
TrueTrueTrueFalseTrueTrueTrueTrueTrue[Finished in 0.010149623965844512s]

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:
TrueTrueFalse[Finished in 0.009970366023480892s]