Python中判断一个值是否为整数 [英] Determining whether an value is a whole number in Python

查看:38
本文介绍了Python中判断一个值是否为整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想确定 Python 中的数值是否为整数.例如,给定:

I would like to determine if a numeric value in Python is a whole number. For example, given:

y = x / 3

我想区分可以被 3 整除的 x 的值.

I want to distinguish between values of x which are evenly divisible by 3 those which are not.

推荐答案

if x % 3 == 0:
    print 'x is divisible by 3'

这篇关于Python中判断一个值是否为整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆