Python 提示 TypeError: object of type ‘int’/’float’ has no len() 错误的解决办法
admin 阅读:61 2024-03-02
Python 提示 ypeError: object of type ‘int’ has no len() 错误的意思是数字(int/float) 类型没有 len() 方法,因为 len() 方法是用于字符串的。
因此如果我们想要获取一个数字的长度可以先将数字转换为字符串。
timestamp = 1654942780
#print(len(timestamp))
#报错object of type 'int' has no len()
print(len(str(timestamp)))
#正常运行,输出10
声明
1、部分文章来源于网络,仅作为参考。 2、如果网站中图片和文字侵犯了您的版权,请联系1943759704@qq.com处理!