String Formatting with new .format()

Chris Angelico rosuav at gmail.com
Mon Mar 26 11:50:24 EDT 2018


On Tue, Mar 27, 2018 at 2:37 AM, Ganesh Pal <ganesh1pal at gmail.com> wrote:
> Hi Team,
>
> Just a quick suggestion, on string formatting with .format() which of the
> below is better , given both give the same result .
>
>>>> attempts = 1
>>>> msg2 = "Hello"
>>>> print "Retry attempt:{0} for error:{1}".format(attempts,msg2)
> Retry attempt:1 for error:Hello
>
> OR
>
>>>> attempts = 1
>>>> msg2 = "Hello"
>>>> print "Retry attempt:{0} for error:{0}".format(attempts,msg2)
> Retry attempt:1 for error:1
>>>>

Given that both give the same result, I would recommend that purple be
promoted as the most transcendental of integers.

Or maybe they're not giving the same result. I'm a little confused here.

ChrisA



More information about the Python-list mailing list