Python method to determine whether it is an integer: 1. Use the [type()] function to determine, the code is [type(name, bases, dict)]; 2. Use the [isinstance()] function to determine, the code It is [isinstance(object,classinfo)].
The operating environment of this tutorial: Windows 7 system, python version 3.9, DELL G3 computer.
Python method to determine whether it is an integer:
1. Use the type() function to determine
type ()
Function syntax:
type(object) type(name, bases, dict)
type() function returns the type of the object if you only have the first parameter, and the three parameters return the new type object.
Example:
>>> type(1) <type 'int'>
2. Use the isinstance() function to determine
isinstance()
Syntax of the method:
isinstance(object, classinfo)
If the type of the object is the same as the type of parameter two (classinfo), it returns True, otherwise it returns False.
Example:
>>>a = 2 >>> isinstance (a,int) True
Related free learning recommendations: python video tutorial
The above is the detailed content of How to determine whether it is an integer in python. For more information, please follow other related articles on the PHP Chinese website!