1

I am trying to print a quotation and the name of the author. My output should look something like the following (including the quotation):

Albert Einstein once said, "A person who never made a mistake never tried anything new."

I tried this:

quote = "A person who never made a mistake never tried anything new."
message = f"Albert Einstein once said, {quote}"
print(message)

But I am not getting quotation, the rest is fine I think.

peacetype
  • 1,928
  • 3
  • 29
  • 49
Maurya
  • 19
  • 4

5 Answers5

1

Try with

quote = '"A person who never made a mistake never tried anything new."'
message = "Albert Einstein once said, {}".format(quote)
print(message)
okie
  • 847
  • 6
  • 18
1

You can do something like this:

>>> quote = "\"A person who never made a mistake never tried anything new.\""
>>> message = f"Albert Einstein once said, {quote}"
>>> print(message)
Albert Einstein once said, "A person who never made a mistake never tried anything new."

Or you can also do something like this:

>>> quote = "A person who never made a mistake never tried anything new."
>>> message = f"Albert Einstein once said, \"{quote}\""
>>> print(message)
Albert Einstein once said, "A person who never made a mistake never tried anything new."

Or you can wrap the double quotes with a single quote to get you to print the double quotes.

Do something like this:

>>> quote = '"A person who never made a mistake never tried anything new."'
>>> message = f"Albert Einstein once said, {quote}"
>>> print(message)
Albert Einstein once said, "A person who never made a mistake never tried anything new."

Note that if you have a single quote inside your sentence, then it will not work. For example, if your sentence said "A person who's never made a mistake never tried anything new", then the single quote won't work.

Joe Ferndz
  • 8,417
  • 2
  • 13
  • 33
  • This perfectly shows the usage of special char, although i think it's a bit complicated to look at. – okie Sep 30 '20 at 06:54
1

Try this

 quote = '"A person who never made a mistake never tried anything new."'
 message = f"Albert Einstein once said, {quote}"
 print(message)
vuun0
  • 153
  • 1
  • 9
1

Try this:

a = "Albert Einstein once said, \"A person who never made a mistake never tried anything new.\""
print(a)

or:

a = 'Albert Einstein once said,"A person who never made a mistake never tried anything new."'
print(a)
cigien
  • 57,834
  • 11
  • 73
  • 112
Tuyet Mai
  • 11
  • 1
0

You need put backslash before the quotation marks.

print("test test hello /" very good /" said him")

Output:

test test hello " very good " said him

cigien
  • 57,834
  • 11
  • 73
  • 112