标签:分片 字符 存在 osi art 单词 row equal tle
>>> format = "Hello,%s,%s enough for ya?" >>> values = (‘world‘,‘Hot‘) >>> print format % values Hello,world,Hot enough for ya?
>>> format = "Pi with three decimals: %.3f" >>> from math import pi >>> print format % pi Pi with three decimals: 3.142
>>> from string import Template >>> s = Template(‘$x,glorious $x!‘) >>> s.substitute(x=‘slurm‘) ‘slurm,glorious slurm!‘
>>> s = Template("It‘s ${x}tastic") >>> s.substitute(x=‘slurm‘) "It‘s slurmtastic"
>>> s = Template("Make $$ selling $x!") >>> s.substitute(x=‘slurm‘) ‘Make $ selling slurm!‘
>>> s = Template(‘A $thing must never $action.‘) >>> d = {} >>> d[‘thing‘] = ‘gentleman‘ >>> d[‘action‘] = ‘show his socks‘ >>> s.substitute(d) ‘A gentleman must never show his socks.‘
>>> ‘%s plus %s equals %s‘ % (1,2,3) ‘1 plus 2 equals 3‘ >>> ‘%s plus % equals %s.‘ % 1,2,3 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: not enough arguments for format string
转换类型 | 含义 |
d,i | 带符号的十进制整数 |
o | 不带符号的八进制 |
u | 不带符号的十进制 |
x | 不带符号的十六进制(小写) |
X | 不带符号的十六进制(大写) |
e | 科学技术法表示的浮点数(小写) |
E | 科学技术法表示的浮点数(大写) |
f,F | 十进制浮点数 |
g | 如果指数大于-4或者小于精度值则和e相同,其他情况与e相同 |
G | 如果指数大于-4或者小于精度值则和e相同,其他情况与E相同 |
C | 单字符(接收整数或者单字符字符串) |
r | 字符串(使用repr转换任意python对象) |
s | 字符串(使用str转换任意python对象) |
>>> ‘Price of eggs: %d‘ % 42 ‘Price of eggs: 42‘ >>> ‘Hexadecimal price of eggs: %x.‘ % 42 ‘Hexadecimal price of eggs: 2a.‘ >>> from math import pi >>> ‘Pi: %f...‘ %pi ‘Pi: 3.141593...‘ >>> ‘Pi: %f...‘ % pi ‘Pi: 3.141593...‘ >>> ‘Very inexact estimate of pi: %i.‘ % pi ‘Very inexact estimate of pi: 3.‘ >>> ‘Using str: %s.‘ % 42L ‘Using str: 42.‘ >>> ‘Using repr: %r.‘ % 42L ‘Using repr: 42L.‘
>>> ‘%10f ‘ % pi #字段宽10 ‘ 3.141593 ‘ >>> ‘%10.2f‘ % pi #字段宽10,精度2 ‘ 3.14‘ >>> ‘%.2f‘ % pi #精度2 ‘3.14‘ >>> ‘%.5s‘ % ‘Guido van Rossum‘ ‘Guido‘
>>> ‘%.*s‘ % (5,‘Guido van Rossum‘) ‘Guido‘
标签:分片 字符 存在 osi art 单词 row equal tle
原文地址:http://www.cnblogs.com/zhangpf/p/7593897.html