Stack Overflow Asked by Maurya on January 11, 2021
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.
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.
Correct answer by Joe Ferndz on January 11, 2021
Try this
quote = '"A person who never made a mistake never tried anything new."'
message = f"Albert Einstein once said, {quote}"
print(message)
Answered by vuun0 on January 11, 2021
Try with
quote = '"A person who never made a mistake never tried anything new."'
message = "Albert Einstein once said, {}".format(quote)
print(message)
Answered by okie on January 11, 2021
You need put backslash before the quotation marks.
print("test test hello /" very good /" said him")
Output: test test hello " very good " said him
Answered by Jerome Palayoor on January 11, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP