码迷,mamicode.com
首页 > 编程语言 > 详细

Python print format() 格式化内置函数

时间:2017-08-30 21:39:08      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:字符串格式化   .com   images   class   语法   位置   logs   通过   详细   

Python2.6 开始,新增了一种格式化字符串的函数 str.format(),它增强了字符串格式化的功能。

基本语法是通过 {} 和 : 来代替以前的 % 。

format 函数可以接受不限个参数,位置可以不按顺序。

技术分享

技术分享

还可以格式化数字:

技术分享

 

 

详细介绍:http://www.runoob.com/python/att-string-format.html

Python print format() 格式化内置函数

标签:字符串格式化   .com   images   class   语法   位置   logs   通过   详细   

原文地址:http://www.cnblogs.com/itfat/p/7455253.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!