[python] The method of judging whether it is an integer: 1. Use the [type()] function to judge, the code is [type(name, bases, dict)]; 2. Use the [isinstance()] function to judge, the code is [isinstance( object, classinfo)].
The operating environment of this tutorial: windows7 system, python3.9 version, DELL G3 computer.
Python's method of determining whether it is an integer:
1. Use the type() function to judge
type()
Function syntax:
|
1
2
|
type(object)
type(name, bases, dict)
|
The type() function returns the type of the object if you have only the first parameter, and the new type object for three parameters.
Example:
|
1
2
|
>>> type(``1``)
<type ``'int'``>
|
2. Use the isinstance() function to judge
isinstance()
Method syntax:
|
1
|
isinstance(object, classinfo)
|
Returns True if the type of the object is the same as the type of the second parameter (classinfo), otherwise returns False.
Example:
|
1
2
3
|
>>>a = ``2
>>> isinstance (a,int)
True
|
Welfare: Reply to [01] by private letter, you can get the python introductory tutorial video for free
The above is the detailed content of how python determines whether it is an integer. For more details, please pay attention to other related articles on the Children's Programming Network!