Python怎么输出整数
发布时间:2021-03-14 编辑:jiaochengji.com
教程集为您提供Python怎么输出整数等资源,欢迎您收藏本站,我们将为您提供最新的Python怎么输出整数资源
Python输出整数的方法:
先使用str()函数将数字转换成字符串赋值给变量i,再用“if i.count('.') == 0”语句判断字符串中是否没有小数点,如果是则输出这个字符串,这样输出的数字就都是整数了
示例代码如下:
x = [23.5, 45.6, 987, 698, 123, 654] for i in x: i = str(i) if i.count('.') == 0: print(i)
执行结果如下:
更多Python知识,请关注:Python自学网!!
您可能感兴趣的文章:
python阶乘怎么写
python怎么控制输入范围内
Python怎么输出整数
python数组下标怎么获取值并输出
python divmod怎么用
python怎么输入整数
python怎么输出小数
阶乘python怎么打
python输入错误怎么删除
python怎么输出列表
上一篇:python怎么在桌面创图标
下一篇:python中如何引用包
[关闭]