Python isinstance function is one of the python built-in functions. Python isinstance() takes in two arguments, and it returns true if the first argument is an instance of the class info given as the second argument.
isinstance() Integer check Example
In the example below, we are checking whether 32 is of int type. It returns true as 32 is int.
num = isinstance(32,int) print(“num is an integer:”, num) |
In the example below, we are checking whether 32 is of str type. It returns false as 32 is int.
num = isinstance(32,str) print(“num is an integer:”, num) |
isinstance() String check Example.
It is same as the above. In the example below, we are checking the weather the given input is a string or not.
string = isinstance(“Hello”,str) print(string) |