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

3
  • 2
    Why asking (pretty much the same thing) twice ( python: SyntaxError: EOL while scanning string literal )? Commented Aug 24, 2010 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. Commented Aug 25, 2010 at 0: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. Commented Aug 25, 2010 at 0:41

4 Answers 4

5

Triple quotes are harder to break.

string1="""blah blah blah "  some'  thi'ng "  end of string """
Sign up to request clarification or add additional context in comments.

1 Comment

+1 although apparently SO's syntax highlighter has just broken it :)
2

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

Comments

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.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.