版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。
版权
方法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