python 如何判断一个数为整数?(判断整数,没有小数)(取余)判断整型 isinstance()
方法1 判断是否为整数(即使不为整型)# -*- coding: utf-8 -*-"""@File: test.py@Time: 2020/6/25 11:27@Author: Dontla@Email: sxana@qq.com@Software: PyCharm"""a = 1.004b = 0.00c = 0.543d = 55print(a % 1 == 0)# Falseprint(b
文章共416字 · 阅读需要大约2分钟
一键AI生成摘要,助你高效阅读
问答
·
方法1 判断是否为整数(即使不为整型)
# -*- coding: utf-8 -*-
"""
@File : test.py
@Time : 2020/6/25 11:27
@Author : Dontla
@Email : sxana@qq.com
@Software: PyCharm
"""
a = 1.004
b = 0.00
c = 0.543
d = 55
print(a % 1 == 0) # False
print(b % 1 == 0) # True
print(c % 1 == 0) # False
print(d % 1 == 0) # True
方法2 判断是否为整型(int)
# -*- coding: utf-8 -*-
"""
@File : test.py
@Time : 2020/6/25 11:27
@Author : Dontla
@Email : sxana@qq.com
@Software: PyCharm
"""
a = 1.004
b = 0.00
c = 0.543
d = 55
print(isinstance(a, int)) # False
print(isinstance(b, int)) # False
print(isinstance(c, int)) # False
print(isinstance(d, int)) # True
更多推荐
已为社区贡献179条内容
所有评论(0)