|  | 
 
 发表于 2022-8-6 16:48:24
|
显示全部楼层 
| '{:+}{:-}'.format(1,-3) '+1-3'
 '{:+}{:-}'.format(1,3)
 '+13'
 '{:+}{:-}'.format(-1,3)
 '-13'
 '{:+}{:-}'.format(-1,-3)
 '-1-3'
 '{:}{: }'.format(-1,-3)
 '-1-3'
 '{: }{: }'.format(1,3)
 ' 1 3'
 '{:,}'.format(1233)
 '1,233'
 '{:_}'.format(1233)
 '1_233'
 '{:_}'.format(1233888)
 '1_233_888'
 {:.3f}.format(4.234667)
 SyntaxError: invalid decimal literal
 '{:.3f}'.format(4.234667)
 '4.235'
 '{:.3g}'.format(4.234667)
 '4.23'
 '{:.6}'.format('ctxnjzhp')
 'ctxnjz'
 '{:.5}'.format(5499)
 Traceback (most recent call last):
 File "<pyshell#13>", line 1, in <module>
 '{:.5}'.format(5499)
 ValueError: Precision not allowed in integer format specifier
 '{:b}'.format(80)
 '1010000'
 '{:c}'.format(80)
 'P'
 '{:d}'.format(80)
 '80'
 '{:o}'.format(80)
 '120'
 '{:x}'.format(80)
 '50'
 '{:#b}'.format(80)
 '0b1010000'
 '{:#o}'.format(80)
 '0o120'
 '{:#x}'.format(80)
 '0x50'
 '{:e}'.format(2.1421)
 '2.142100e+00'
 '{:E}'.format(2.1421)
 '2.142100E+00'
 '{:f}'.format(2.1421)
 '2.142100'
 '{:g}'.format(2.1421)
 '2.1421'
 '{:g}'.format(123456789)
 '1.23457e+08'
 '{:g}'.format(12.3456789)
 '12.3457'
 '{:%}'.format(12.34)
 '1234.000000%'
 '{:.2%}'.format(12.34)
 '1234.00%'
 '{:.(qq)f}'.format(1.456,qq=3)
 Traceback (most recent call last):
 File "<pyshell#30>", line 1, in <module>
 '{:.(qq)f}'.format(1.456,qq=3)
 ValueError: Format specifier missing precision
 '{:.(qqw)f}'.format(1.456,qq=3)
 Traceback (most recent call last):
 File "<pyshell#31>", line 1, in <module>
 '{:.(qqw)f}'.format(1.456,qq=3)
 ValueError: Format specifier missing precision
 '{:.(qqw)f}'.format(1.456,qqw=3)
 Traceback (most recent call last):
 File "<pyshell#32>", line 1, in <module>
 '{:.(qqw)f}'.format(1.456,qqw=3)
 ValueError: Format specifier missing precision
 '{:.(qqw)f}'.format(1.4564,qqw=3)
 Traceback (most recent call last):
 File "<pyshell#33>", line 1, in <module>
 '{:.(qqw)f}'.format(1.4564,qqw=3)
 ValueError: Format specifier missing precision
 '{:.(prec)f}'.format(1.4564,prec=2)
 Traceback (most recent call last):
 File "<pyshell#34>", line 1, in <module>
 '{:.(prec)f}'.format(1.4564,prec=2)
 ValueError: Format specifier missing precision
 '{:.{qq}f}'.format(1.456,qq=3)
 '1.456'
 '{:.{qq}f}'.format(1.456,qq=2)
 '1.46'
 "{:{fill}{align}{width}.{prec}{ty}}".format(3.1415, fill='+', align='^', width=10, prec=3, ty='g')
 '+++3.14+++'
 year=1999
 f 'ctx出生于{year}nian'
 SyntaxError: invalid syntax
 f'ctx出生于{year}nian'
 'ctx出生于1999nian'
 f'4+8={4+8},2dfp={2*2},3dlf={3*3*3}
 SyntaxError: unterminated string literal (detected at line 1)
 f'4+8={4+8},2dfp={2*2},3dlf={3*3*3}'
 '4+8=12,2dfp=4,3dlf=27'
 f'{-322,012}'
 SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers
 f'{-320,012}'
 SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers
 f'{-320:012}'
 SyntaxError: invalid decimal literal
 f'{-320:012}'
 '-00000000320'
 '{:,}'format(123456789)
 SyntaxError: invalid syntax
 '{:,}'.format(123456789)
 '123,456,789'
 f'{123456789:_}'
 '123_456_789'
 '{:.{qq}f}'.format(1.456,qq=2)
 '1.46'
 f'{1.456:{qq}f}'
 Traceback (most recent call last):
 File "<pyshell#51>", line 1, in <module>
 f'{1.456:{qq}f}'
 NameError: name 'qq' is not defined
 f'{1.456:.2f}'
 '1.46'
 '{:.3f}'.format(1.4224)
 '1.422'
 f'{1.4224:.3f}'
 '1.422'
 | 
 |