String Formatting with new .format()

Ganesh Pal ganesh1pal at gmail.com
Wed Mar 28 10:30:34 EDT 2018


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


My Bad and Apologies  , I should be fined for pasting wrong question.

 Actually I wanted to know if its ok to use just empty {}  with .format()
or  use {} with values i.e {0} {1} both will give the same results anyway

Example:

>>> attempts =1
>>> msg2 = "Hello"
>>> print "Retry attempt:{} for error:{}".format(attempts,msg2)  //  Empty
{}
Retry attempt:1 for error:Hello

>>> attempts =1
>>> msg2 = "Hello"
>>> print "Retry attempt:{0} for error:{1}".format(attempts,msg2) // With
Values
Retry attempt:1 for error:Hello
>>>


Regards,
Ganesh



More information about the Python-list mailing list