格式化字符串中的多种值格式
Multiple value-formats in a formatted string
是否可以组合多个冒号格式字符串?
示例:
val = 2.123
print(f'This is a float-value with one digit: {val:.1f} and balanced to right with {val:>10}')
所以,类似 {val:.1f:>10} 的东西?
参考Format Specification Mini Language。您刚刚完成订单,f'{val:>10.1f}'
适用于此特定示例。
>
是对齐,10
是宽度,.1
是精度,f
是类型。
是否可以组合多个冒号格式字符串? 示例:
val = 2.123
print(f'This is a float-value with one digit: {val:.1f} and balanced to right with {val:>10}')
所以,类似 {val:.1f:>10} 的东西?
参考Format Specification Mini Language。您刚刚完成订单,f'{val:>10.1f}'
适用于此特定示例。
>
是对齐,10
是宽度,.1
是精度,f
是类型。