How to determine whether a number is an integer in python

爱喝马黛茶的安东尼
Release: 2019-06-20 10:01:25
Original
44375 people have browsed it

How to determine whether a number is an integer in python? In fact, Python has two ways to check the type of a variable: the type() function can directly return the variable type; the isinstance() function can be used to determine the type of the variable and returns a Boolean value.

How to determine whether a number is an integer in python

isinstance() function

can be used to determine the type of a variable. It returns a Boolean value. False or True.

Related recommendations: "Python Video Tutorial"

>>>isinstance("123",str)
>>>Flase
>>>isinstance(123,int)
>>>True
>>>isinstance({'123'},list)
>>>False
>>>isinstance(['123'],int)
>>>False
Copy after login

Int, float, etc. are all basic variable types. In fact, classes are also a type of variables. .

type() function

does not determine the type of the variable, but directly returns the type of the variable

>>> type(123)
Copy after login

The above is the detailed content of How to determine whether a number is an integer in python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!