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

  • Home
  • SEARCH
  • 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 6188977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:19:46+00:00 2026-05-24T02:19:46+00:00

I searched the site but it seems like this exercise from the book Learn

  • 0

I searched the site but it seems like this exercise from the book Learn Python the Hard way wasn’t covered in previous questions.

I have this exercise:

1)Find all the places where a string is put inside a string. There are four places.
2)Are you sure there’s only four places? How do you know? Maybe I like lying.

x = "There are %d types of people." % 10
binary = "binary"
do_not = "don't"
y = "Those who know %s and those who %s." % (binary, do_not) #two strings inside a string, count is 2

print x
print y

print "I said: %r." % x #here, count is 3
print "I also said: '%s'." % y #here, count is 4

hilarious = False
joke_evaluation = "Isn't that joke so funny?! %r"

print joke_evaluation % hilarious

w = "This is the left side of..."
e = "a string with a right side."

print w + e

I tried to solve it and commented the lines where I found a string inside a string(found4). But, the author’s second questions makes me worry I haven’t found all. Have I miss something? If yes, can you please tell me what?

  • 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-05-24T02:19:47+00:00Added an answer on May 24, 2026 at 2:19 am

    If you interpret “putting a string inside a string” as “using a format character with a string argument”, you correctly identified all four occurrences. It may be more helpful to put away the useless instructions and explain what happens. For more information, have a look at the offical documentation for formatting characters. I’ll try to include some helpful exercises without trick questions.

    x = "There are %d types of people." % 10
    

    %d is the formatting character for a Signed integer decimal (what most people think of when hearing a “number”). 10 is expressed in decimal and inserted into the string, resulting in the string There are 10 types of people..

    Excercise: What would "7+6: %d" % (7+6) result in? Test it in your Python shell.
    Excercise: What would "0x12: %d" % 0x12 result in? Test it in your Python shell.
    Hint: A prefix of 0x means the following number is hexadecimal, i.e. base 16 instead of 10.

    binary = "binary"
    do_not = "don't"
    y = "Those who know %s and those who %s." % (binary, do_not)
    

    %s inserts the string representation of a value. This example goes to show that if there is more than one %d, %s or so in a format string, we need to give that number of arguments, in a tuple or list. The difference between a tuple (round, braces) and a list [square, braces] is that a tuple is immutable(i.e. can’t be changed), but a list can.

    Excercise: Given the tuple x = ('world', 'Hello'), construct a tuple y with the correct order of words. Dive Into Python’s introduction of tuples will help you understand the basics of tuples.

    print "I said: %r." % x
    

    %r is the representation of a value, ideally something you could enter into a Python shell. You can get the same representation with the repr function. For example, repr("a") == "'a'", whereas str(a) == "a". For most types except string, the result of repr and str (or %r and %s in format strings) is the same.

    print w + e
    

    This concatenates two strings (i.e. puts one after the other). Note that the + means something else (addition) if both arguments are numbers.

    Excercise: What is the result of "3" + "4"? Test it in your Python shell.
    Excercise: Given x = "3"; y = "4", print out the sum 7 (Hint).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I searched everywhere from google to this site but seems no answer for it.
Preface: I am sure this is incredibly simple, but I have searched this site
I've searched within the site, but couldn't find my answer.. I'd like to start
I have searched google, but I didn't find anything. I searched this site and
I'd like a true WYSIWYG experience from CKEditor, but it seems that since the
This seems like a trivial problem, but my web searches for an answer (even
I've searched this site and the web and just looking for a simple example
I have searched this site and Google and even though the idea is pretty
Searched a lot about this problem but never found a answer, that solved it.
I've tried to understand this, and searched SO for similar questions, but I still

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.