Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8375203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:06:52+00:00 2026-06-09T15:06:52+00:00

This snippet: formatter = %r %r %r %r print formatter % ( I had

  • 0

This snippet:

formatter = "%r %r %r %r"
print formatter % (
    "I had this thing.",
    "That you could type up right.",
    "But it didn't sing.",
    "So I said goodnight."
)

when run, prints this string:

'I had this thing.' 'That you could type up right.' "But it didn't sing." 'So I said goodnight.'

Why did "But it didn't sing." get put in double quotes when the other three items were in single quotes?

(This code is taken from Learn Python the Hard Way Exercise 8.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:06:54+00:00Added an answer on June 9, 2026 at 3:06 pm

    Python is clever; it’ll use double quotes for strings that contain single quotes when generating the representation, to minimize escapes:

    >>> 'no quotes'
    'no quotes'
    >>> 'one quote: \''
    "one quote: '"
    

    Add a double quote in there as well and it’ll revert back to single quotes and escape any single quotes contained:

    >>> 'two quotes: \'\"'
    'two quotes: \'"'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This snippet throws an NullPointerException due to the fact that its unboxed to a
Consider this snippet: globalVar = 25 def myfunc(paramVar): localVar = 30 print Vars: {globalVar},
In this snippet: find( sub { print found . $File::Find::name . \n; }, (.));
I have this code snippet: DateFormat formatter1; formatter1 = new SimpleDateFormat(mm/DD/yyyy); System.out.println((Date)formatter1.parse(08/16/2011)); When I
This snippet of code always parses the date into the current timezone, and not
This snippet from official website works as expected: $treeObject = Doctrine::getTable('Category')->getTree(); $rootColumnName = $treeObject->getAttribute('rootColumnName');
In this snippet of Google Closure javascript code involving a constructor, why is goog.base(this);
Consider this snippet of code: public static class MatchCollectionExtensions { public static IEnumerable<T> AsEnumerable<T>(this
I've tested this snippet with 3 different TTF fonts and I still din't get
I have this snippet of shell script: am start -n com.android.gallery3d/com.android.gallery3d.app.MovieActivity -d /sdcard/movie.mp4 sleep

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.