Python Question About Format Specifiers

  • From: "Homme, James" <james.homme@xxxxxxxxxxxx>
  • To: "programmingblind@xxxxxxxxxxxxx" <programmingblind@xxxxxxxxxxxxx>
  • Date: Mon, 6 Jun 2011 15:18:20 -0400

Hi,
My goal in this program is to properly explain above lines what they are doing. 
I'm unsure what goes on with the last line. I see what it's doing when I run 
the program, but I don't know why it's doing it.

# Get some input from the user and work with it.
#
# Print and use a comma to make the input go to the same line as the question.
print "How old are you?",
# Get input and put it into age.
age = raw_input()
# Now, give the prompt and get the input all at once.
# Note that now we have to put a space at the end of the quoted string.
height = raw_input("How tall are you? ")
# Now do it again.
weight = raw_input("How much do you weigh? ")
# Now print out the variables with raw string format specifiers.
# This turns them into single quoted strings properly formatted.
print "So, you're %r old, %r tall and %r heavy." % ( age, height, weight)
# I'm unsure how changing this to %s does what it does.
print "So number 2, you're %s old, %s tall and %s heavy." % ( age, height, 
weight)

Thanks.

Jim
Jim Homme,
Usability Services,
Phone: 412-544-1810.


________________________________
This e-mail and any attachments to it are confidential and are intended solely 
for use of the individual or entity to whom they are addressed. If you have 
received this e-mail in error, please notify the sender immediately and then 
delete it. If you are not the intended recipient, you must not keep, use, 
disclose, copy or distribute this e-mail without the author's prior permission. 
The views expressed in this e-mail message do not necessarily represent the 
views of Highmark Inc., its subsidiaries, or affiliates.

Other related posts: