|
发表于 2022-8-6 11:46:42
|
显示全部楼层
year=1999
'ctx出生于year年'
'ctx出生于year年'
'ctx出生于{}年'.format(year)
'ctx出生于1999年'
1
1
'1+4={},2pf{},5lf{}'.format{1+4,2*2,5*5*5}
SyntaxError: invalid syntax
'1+4={},2pf{},5lf{}'.format(1+4,2*2,5*5*5)
'1+4=5,2pf4,5lf125'
{1}看到{0}好开心'
SyntaxError: unexpected indent
'{1}看到{0}好开心'.format('ctx','njz')
'njz看到ctx好开心'
'{}{}{}{}{}'.format('整','齐')
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
'{}{}{}{}{}'.format('整','齐')
IndexError: Replacement index 2 out of range for positional args tuple
'{0}{0}{1}{1}'.format('整','齐')
'整整齐齐'
'我是{c},我喜欢{z}'.format(z='njz',c='ctx')
'我是ctx,我喜欢njz'
'我是{n},我喜欢{0},喜欢{0}是个人的自由'.format('sw',name=ctx)
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
'我是{n},我喜欢{0},喜欢{0}是个人的自由'.format('sw',name=ctx)
NameError: name 'ctx' is not defined
'我是{n},我喜欢{0},喜欢{0}是个人的自由'.format('sw',name='ctx')
Traceback (most recent call last):
File "<pyshell#12>", line 1, in <module>
'我是{n},我喜欢{0},喜欢{0}是个人的自由'.format('sw',name='ctx')
KeyError: 'n'
'我是{n},我喜欢{0},喜欢{0}是个人的自由'.format('sw',n='ctx')
'我是ctx,我喜欢sw,喜欢sw是个人的自由'
'{},{},{}'.format(1,'{}',13213)
'1,{},13213'
'{},{{}},{}'.format(1,5)
'1,{},5'
{:^}.format(250)
SyntaxError: invalid syntax
{:^}.format(250)
SyntaxError: invalid syntax
'{:^}'.format(250)
'250'
'{:^}'.format(25)
'25'
'{:^}'.format(2)
'2'
'{:^}'.format(25000)
'25000'
'{1:>8}{2:<8}'.format(121,212)
Traceback (most recent call last):
File "<pyshell#22>", line 1, in <module>
'{1:>8}{2:<8}'.format(121,212)
IndexError: Replacement index 2 out of range for positional args tuple
'{1:>8}{2:<8}'.format(261,250)
Traceback (most recent call last):
File "<pyshell#23>", line 1, in <module>
'{1:>8}{2:<8}'.format(261,250)
IndexError: Replacement index 2 out of range for positional args tuple
'{1:>8}{2:<8}'.format(520,250)
Traceback (most recent call last):
File "<pyshell#24>", line 1, in <module>
'{1:>8}{2:<8}'.format(520,250)
IndexError: Replacement index 2 out of range for positional args tuple
'{1:>10}{2:<10}'.format(520,250)
Traceback (most recent call last):
File "<pyshell#25>", line 1, in <module>
'{1:>10}{2:<10}'.format(520,250)
IndexError: Replacement index 2 out of range for positional args tuple
'{:^10}'.format(250)
' 250 '
"{1:>10}{0:<10}".format(520, 250)
' 250520 '
'{1:>10}{2:<10}'.format(520,250)
Traceback (most recent call last):
File "<pyshell#28>", line 1, in <module>
'{1:>10}{2:<10}'.format(520,250)
IndexError: Replacement index 2 out of range for positional args tuple
'{1:>10}{0:<10}'.format(520,250)
' 250520 '
'{1:>10}{0:<10}'.format(1,2)
' 21 '
'{1:>10}{0:<10}'.format(a,b)
Traceback (most recent call last):
File "<pyshell#31>", line 1, in <module>
'{1:>10}{0:<10}'.format(a,b)
NameError: name 'a' is not defined
'{1:>10}{0:<10}'.format('a','b')
' ba '
'{l:>10}{r:<10}'.format('a','b')
Traceback (most recent call last):
File "<pyshell#33>", line 1, in <module>
'{l:>10}{r:<10}'.format('a','b')
KeyError: 'l'
'{l:>10}{r:<10}'.format(r='a',l='b')
' ba '
'{l:>10}{r:<10}'.format(l=1,r=2)
' 12 '
'{1:>10}{0:<10}'.format(250,520)
' 250520 '
SyntaxError: multiple statements found while compiling a single statement
'{1:>10}{0:<10}'.format(250,520)
' 520250 '
'{1:>10}{0:<10}'.format(44,33)
' 3344 '
'{:05}'.format(5)
SyntaxError: unexpected indent
'{:010}'.format(5)
'0000000005'
'{:>010}'.format(5)
'0000000005'
'{:<010}'.format(5)
'5000000000'
'{:<08}'.format(5)
'50000000'
'{:<08}'.format(-5)
'-5000000'
'{:08}'.format(-5)
'-0000005'
'{1:!>10}{0:<!10}'.format(250,520)
Traceback (most recent call last):
File "<pyshell#46>", line 1, in <module>
'{1:!>10}{0:<!10}'.format(250,520)
ValueError: Invalid format specifier
'{1:!>10}{0:<!10}'.format(420,240)
Traceback (most recent call last):
File "<pyshell#47>", line 1, in <module>
'{1:!>10}{0:<!10}'.format(420,240)
ValueError: Invalid format specifier
|
|