之前向大家介绍过Python中float() 函数的实现过程(https://www.py.cn/jishu/jichu/21933.html)。在使用float() 函数时,我们用的字符是浮点数,但是有时我们并不需要浮点数,这时我们就要将float转化为其他形式。本文将介绍Python float 转换为 String的两种方法:使用'%d'%num实现和使用str()方法实现。
方法一:使用'%d'%num实现
1 2 3 4 5 6 7 8 9 10 |
|
方法二:使用str()方法实现
1 2 3 4 5 6 7 |
|
输出
1 2 |
|
以上就是Python中将float 转换为 String的两种方法,都是很简单的方法,大家可以选择喜欢喜欢的方法进行转换哦~