0

i have quotes inside a string like this

string1="blah blah blah "  some'  thi'ng "  end of string "

how do i make sure the quotes are included in there?

please note i have both doubel and single quotes in there

Alex Gordon
  • 57,446
  • 287
  • 670
  • 1,062
  • 2
    Why asking (pretty much the same thing) twice ( [python: SyntaxError: EOL while scanning string literal](http://stackoverflow.com/questions/3561691/python-syntaxerror-eol-while-scanning-string-literal) )? – Bertrand Marron Aug 24 '10 at 23:13
  • 1
    @Bertrand Marron: They seem like very distinct (albeit very basic) questions to me, one dealing with a string that runs on for multiple lines, the other on how to escape multiple quote forms in a single string. The answer may be the same, but for different reasons. – Nick T Aug 25 '10 at 00:21
  • 4
    @Nick T: The OP posted this question a couple minutes after posting the other one. Probably after realizing what his mistake was. It would have been a better idea to edit the other question and not post another one. Plus, if you take a look at his user profile, you'll see that he's been asking questions every ten minutes about **very** similar topics. – Bertrand Marron Aug 25 '10 at 00:41

4 Answers4

5

Triple quotes are harder to break.

string1="""blah blah blah "  some'  thi'ng "  end of string """
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
2

You can use \" to make quotes not break quotes.

wheaties
  • 35,646
  • 15
  • 94
  • 131
1

if you don't want to go through the whole string putting a backslash before every offending quote, i'd enclose the string in triple quotes. this is especially good for a string that will span several lines.

aeroNotAuto
  • 260
  • 3
  • 13
0

You can use \" for using double quotes within double quoted string.

string1 = "blah blah blah \"  some'  thi'ng \"  end of string "

OR you can use ' single quotes for declaring string:

string1 = 'blah blah blah \"  some'  thi'ng \"  end of string '

OR you can use """ triple quotes for string declaration:

string1 = """blah blah blah \"  some'  thi'ng \"  end of string """

Refer article about String Literals for getting complete list of escape sequences

Moinuddin Quadri
  • 46,825
  • 13
  • 96
  • 126