Python学习【第7篇】:字符串拼接

1.格式化字符有%s,%d,%f浮点数

%s代表格式化字符串,s是string意思

msg = 'my name is %s'%"xiaoxing"
print(msg)
运行结果:
my name is xiaoxing

%d代表整型数据int
msg = 'my name is %s,age:%d'%("xiaoxing",22)
print(msg)
运行结果:
my name is xiaoxing,age:22

%f 代表浮点数
tp_1 = "年利率为%f"%23.123456789
print(tp_1)
运行结果:
年利率为23.123457
默认进行四舍五入,保留六位小数

tp_1 = "年利率为%.2f"%23.123456789
print(tp_1)
运行结果:
年利率为23.12
可以通过.2进行控制四舍五入后保留的小数位


Format字符串
http://www.cnblogs.com/wupeiqi/articles/5484747.html

 

posted on 2018-05-26 15:43  小星1995  阅读(116)  评论(0编辑  收藏  举报

导航