python3 format()格式化函数

a = "Python"
b = "="
c = ">"
print("{0:{1}{3}{2}}".format(a, b, 25, c))
print("{0:=>25}".format(a, b, 25, c))

1

{0(format参数索引):(相当于python2中的%)=(空格处填充)>(’:'前的东西右对齐)25(最小宽度)}

2

{:e}与{0:e}是一样的,即:之前的索引默认为0

小例子:

>>> '{:,}'.format(100000000000000000000000)
'100,000,000,000,000,000,000,000'
>>> 

‘{: - <^>(不能缺否则会报错:ValueError: Invalid format specifier) 50 , . 2 bcdoxX eEf%}’.format(100000000000000000000000)

a = "Python"
b = "="
c = ">"
print("{0:{1}{3}{2}}".format(a, b, 25, c))

你可能感兴趣的:(Python)