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.123456789print(tp_1)运行结果:年利率为23.123457默认进行四舍五入,保留六位小数
tp_1 = "年利率为%.2f"%23.123456789print(tp_1)运行结果:年利率为23.12可以通过.2进行控制四舍五入后保留的小数位 Format字符串http://www.cnblogs.com/wupeiqi/articles/5484747.html
原文地址:https://www.cnblogs.com/star520/p/9093084.html
时间: 2024-10-31 02:39:02