RE: Python Question About Format Specifiers

  • From: "Harmony Neil" <harmonylm@xxxxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Mon, 6 Jun 2011 20:40:42 +0100

You can also use %d I think.

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of David Tseng
Sent: 06 June 2011 20:36
To: programmingblind@xxxxxxxxxxxxx
Subject: Re: Python Question About Format Specifiers

http://stackoverflow.com/questions/1436703/difference-between-str-and-repr-i
n-python

In other words, it's the difference between repr() and str().

On 6/6/11, Homme, James <james.homme@xxxxxxxxxxxx> wrote:
> 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.
>
__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: