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

Python内置函数之format()

时间:2017-08-14 11:35:26      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:十六进制   for   span   保留   十进制   格式化   code   二进制   orm   

format(value[,format_spec])
返回字符串对象。

可以用来格式化value。

>>> format(12,0.3f) #保留3位小数
12.000
>>> {2}.format(hello,i,am,tom) #格式化字符串
am

还可以用来进制转化:

>>> format(3,b) #二进制转化
11
>>> format(3,d) #十进制转化
3
>>> format(3,n) #十进制转化
3
>>> format(3,x) #十六进制转化
3
>>> format(12,x)
c
>>> format(12,o) #8进制转化
14

 

Python内置函数之format()

标签:十六进制   for   span   保留   十进制   格式化   code   二进制   orm   

原文地址:http://www.cnblogs.com/leomei91/p/7356596.html

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