Let's check some related built-in functions which we'll be needing later on such as type()
, isinstance()
, id()
and dir()
.
Parameters:
Explanation: This function is used for type checking, it returns the class name of an object.
a = "What?"
print(type(a)) # str
b = 5.0
print(type(b)) # float
Parameters:
class
: Any class.Explanation: This function checks if an object is an instance of a particular class. Returns True
/False
.
a = 23
print(isinstance(a, int)) # True
print(isinstance(a, float)) # False
print(isinstance(a, str)) # False
Parameters:
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.
my_float = 50.0
print(id(my_float)) # 1875526208176
Parameters:
Explanation: Returns a list
containing names of variables in an object and functions supported by that object.
## Names under current local scope
print(dir())
## List of object's attributes
print(dir(int))
print(dir(str))