[Tutor] Python = {0}.format
Ben Finney
ben+python at benfinney.id.au
Mon Aug 18 00:32:57 CEST 2014
abid saied <abidsaied at gmail.com> writes:
> I’m in the process of teaching myself python.
Congratulations, and welcome.
> Can someone have a look at the text in red and explain please.
Text comes through as text. Don't rely on fonts, colours, or other
non-text markup to survive.
If you want to draw attention to some part of code, it is much better to
reduce the example so it is minimal enough to show only what is
relevant, while still exhibiting the behaviour you want to discuss.
> print("The original quote is: {0}".format(quote))
> print("The new quote is:{0}".format(quote.replace(replaceWord,replaceWith)))
> # Not sure what the {0}.format is doing
Every value in Python is an object, with methods according to its type.
A text string has many methods
<URL:https://docs.python.org/3/library/stdtypes.html#string-methods>.
The ‘format’ method of the ‘str’ type is used to generate formatted
output from a template string. See
<URL:https://docs.python.org/3/library/stdtypes.html#str.format> and
<URL:https://docs.python.org/3/library/string.html#formatstrings>.
--
\ “I have yet to see any problem, however complicated, which, |
`\ when you looked at it in the right way, did not become still |
_o__) more complicated.” —Paul Anderson |
Ben Finney
More information about the Tutor
mailing list