python中将数值写入字符串的两种方式

a=int(5)
b=float(4.3)
c=0.005

str1='%d %.4f %.2e'%(a,b,c)#这种方式可以在一个长字符串中同时插入多个数值型数据
str2='int is {}'.format(str(a))#使用format方式只允许插入一个,用字符串代替{}花括号

print(str1)
print(str2)

'''
5 4.3000 5.00e-03
int is 5

'''

猜你喜欢

转载自blog.csdn.net/WYXHAHAHA123/article/details/86999628