New Python 3.0 string formatting - really necessary?

MRAB google at mrabarnett.plus.com
Sat Dec 20 19:17:39 EST 2008


r wrote:
> Walter,
> 
> Would you be kind enough to translate this code to the new syntax?
> 
>>>> s = 'python'
>>>> n = 12
>>>> f = 1.333333333
>>>> '%s %05d %0.2f' %(s,n,f)
> 'python 00012 1.33'
> 
> i want to see how casting is handled. Thanks
> 
 >>> '{0} {1:05} {2:.2}'.format(s, n, f)
'python 00012 1.3'




More information about the Python-list mailing list