2.7 Some built-in functions

Let's check some related built-in functions which we'll be needing later on such as type(), isinstance(), id() and dir().

1. type(object) => str

Parameters:

  • >object object: Any object.

Explanation: This function is used for type checking, it returns the class name of an object.

2. isinstance(object, class) => bool

Parameters:

  • >object object: Any object.
  • >class class: Any class.

Explanation: This function checks if an object is an instance of a particular class. Returns True/False.

3. id(object) => int

Parameters:

  • >object object: Any object.

Explanation: This function returns the object's identity (id) and every object has a unique id. The identity is simply the representation of an object's address in the memory (where it is stored). The returned object's id varies across programs/systems, so will not be the same anytime.

4. dir(object) => list

Parameters:

  • >object object: Any object.

Explanation: Returns a list containing names of variables in an object and functions supported by that object.