types and objects is operator compares the identity of two objects the built-in function type(returns the type of an object here' an example of different ways you might compare two objectscompare two objects def compare( , )if is ba and are the same object statements if =ba and have the same value statements if type(ais type( ) and have the same type statements the type of an object is itself an object known as the object' class this object is uniquely defined and is always the same for all instances of given type thereforethe type can be compared using the is operator all type objects are assigned names that can be used to perform type checking most of these names are built-inssuch as listdictand file here' an exampleif type(sis lists append(itemif type(dis dictd update(tbecause types can be specialized by defining classesa better way to check types is to use the built-in isinstance(objecttypefunction here' an exampleif isinstance( ,list) append(itemif isinstance( ,dict) update(tbecause the isinstance(function is aware of inheritanceit is the preferred way to check the type of any python object although type checks can be added to programtype checking is often not as useful as you might imagine for oneexcessive checking severely affects performance secondprograms don' always define objects that neatly fit into an inheritance hierarchy for instanceif the purpose of the preceding isinstance( ,liststatement is to test whether is "list-like,it wouldn' work with objects that had the same programming interface as list but didn' directly inherit from the built-in list type another option for adding type-checking to program is to define abstract base classes this is described in reference counting and garbage collection all objects are reference-counted an object' reference count is increased whenever it' assigned to new name or placed in container such as listtupleor dictionaryas shown herea [ append(bcreates an object with value increases reference count on increases reference count on lib fl ff