Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using quotation marks inside quotation marks

When I want to do a print command in Python and I need to use quotation marks, I don't know how to do it without closing the string.

For instance:

print " "a word that needs quotation marks" " 

But when I try to do what I did above, I end up closing the string and I can't put the word I need between quotation marks.

How can I do that?

like image 653
Thi G. Avatar asked Jan 29 '12 02:01

Thi G.


People also ask

How do you quote within a quote within a quote?

If the quotation enclosed in single marks also contains material–whether another quotation or the title of a work–that needs to be set off with quotation marks, use double quotation marks around that material. The pattern is double, single, double quotation marks.

How do you quote something that already has quotation marks?

Quoting a Quote That is to say, what do you do when you're quoting material that already contains a quote? The principle doesn't change. In American English, use double quotes for the outside quote and single quotes for the inside quote. In British English, do the opposite.

What are the 3 rules for using quotations?

Do commas and periods go inside or outside quotation marks? Commas and periods always go inside the quotation marks in American English; dashes, colons, and semicolons almost always go outside the quotation marks; question marks and exclamation marks sometimes go inside, sometimes stay outside.

How do you quote multiple quotes in one sentence?

'” When multiple quotation marks are used for quotations within quotations, keep the quotation marks together (put periods and commas inside both; put semi-colons, colons, etc., outside both).


1 Answers

You could do this in one of three ways:

  1. Use single and double quotes together:

    print('"A word that needs quotation marks"') "A word that needs quotation marks" 
  2. Escape the double quotes within the string:

    print("\"A word that needs quotation marks\"") "A word that needs quotation marks"  
  3. Use triple-quoted strings:

    print(""" "A word that needs quotation marks" """) "A word that needs quotation marks"  
like image 100
Jamie Forrest Avatar answered Oct 21 '22 11:10

Jamie Forrest