数字转字符串
str(111)
字符串转数字
def transToNum(s):
""" 字符串转数字 """
if s.isnumeric():
return int(s)
# 处理负数
elif len(s) > 1 and s[1:].isnumeric() and s[0] == '-':
return int(s)
# 处理小数
else:
return float(s)
最后
以上就是难过小海豚最近收集整理的关于python3字符串与数字转换的全部内容,更多相关python3字符串与数字转换内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复