[Tutor] func-question_y_n.py
Alan Gauld
alan.gauld at btinternet.com
Sun Mar 17 20:41:32 CET 2013
On 17/03/13 17:40, Christopher Emery wrote:
> Could you point me to a really good and easy to under about string
> formatting? I am what I would say in programming a baby still on
> milk. (smile)
You'll find an introduction to old style formatting in my
tutorial topic "Simple Sequences".
In that style you would write your print statement as:
print("Your response was %s! Please enter %s or %s for your response!"
% (answer, p, n) ) # note can be one line...
I only wrapped the line for email formatting...
In new style (V3) formatting your line looks like:
print("Your response was {0}! \
Please enter {1} or {2} for your response!".format(answer, p, n) )
Again it should be one line.
V3 formatting is described here:
http://docs.python.org/3/library/string.html#formatstrings
And to make it more real, here are the examples:
http://docs.python.org/3/library/string.html#formatexamples
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list