python 3 format()フォーマット関数

715 ワード

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パラメータインデックス):(python 2の%に相当)=(スペースに記入)>(’:'前のものを右揃え)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))