#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    1
    Rep Power
    0

    Odd double-quote


    Why does this:
    Code:
    formatter = "%r %r %r %r"
    
    print formatter % (1, 2, 3, 4)
    print formatter % ("one", "two", "three", "four")
    print formatter % (True, False, False, True)
    print formatter % (formatter, formatter, formatter, formatter)
    print formatter % (
        "I had this thing.",
        "That you could type up right.",
        "But it didn't sing.",
        "So I said goodnight."
    )
    , when ran, gives this string : "But it didn't sing." as double quotes and the rest as single quotes?

    This code is taken from http://learnpythonthehardway.org exercise 8.
  2. #2
  3. JavaScript is not spelt java
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2011
    Location
    Landan, England
    Posts
    743
    Rep Power
    165
    That is to be expected, because of the apostrophe '.
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,966
    Rep Power
    481
    clever python.

    Would you prefer the incorrect
    'But it didn't sing.'
    Or the lengthy
    'But it didn\'t sing.'
    I'd say python worked well.

    Code:
    >>> '"They\'d go" said she.'
    '"They\'d go" said she.'
    >>> "\"They'd go\" said she."
    '"They\'d go" said she.'
    >>>
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo