What does {0} mean in this Python string?

What does {0} mean in this Python string?

Its an indicator to the format method that you want it to be replaced by the first (index zero) parameter of format. (eg 2 + 2 = {0}.format(4))

Its a boon for placing same arg multiple times

print(When you multiply {0} and {1} or {0} and {2}, the result is {0}.format(0,1,2))

Isnt this nice!!!

What does {0} mean in this Python string?

http://docs.python.org/release/3.1.3/library/stdtypes.html#str.format

Perform a string formatting operation. The format_string argument can
contain literal text or replacement fields delimited by braces {}.
Each replacement field contains either the numeric index of a
positional argument, or the name of a keyword argument. Returns a copy
of format_string where each replacement field is replaced with the
string value of the corresponding argument.

Leave a Reply

Your email address will not be published.