Il est difficile de revoir le document, alors ne notez que les parties nécessaires.
{: <nombre}
{:> Numbers}
{: ^ Number}
{: caractères remplis ^ nombres}
>>> '{:<30}'.format('left aligned')
'left aligned '
>>> '{:>30}'.format('right aligned')
' right aligned'
>>> '{:^30}'.format('centered')
' centered '
>>> '{:*^30}'.format('centered')
'***********centered***********'
{: d}
{: x}
ou {: # x}
{: b}
ou {: # b}
>>> "int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}".format(42)
'int: 42; hex: 2a; oct: 52; bin: 101010'
>>> "int: {0:d}; hex: {0:#x}; oct: {0:#o}; bin: {0:#b}".format(42)
'int: 42; hex: 0x2a; oct: 0o52; bin: 0b101010'
>>> "{:,}".format(1000000)
'1,000,000'
>>> urldata = {"scheme":"http","netloc":"qiita.com","path":"/drafts"}
>>> url = "{scheme}://{netloc}{path}".format(urldata)
** «0.» ** est important.
>>> url = "{0.scheme}://{0.netloc}{0.path}".format(urldata)
>>> import datetime
>>> d = datetime.datetime(2010, 7, 4, 12, 15, 58)
>>> '{:%Y-%m-%d %H:%M:%S}'.format(d)
'2010-07-04 12:15:58'
Recommended Posts