0

As you know that python support both ' and " for string like

a = 'str'
b = "str"

If I want to represent the symbol ", I can use:

a = '"'

However, I don't want to use ', is there any way? In java, which does not allow ' for string representing, I can use:

a = "\""

but this escape won't work in python

print("\"") # >>> \"

Thanks

7
  • 2
    That is not what print("\"") prints. Commented Jul 12, 2019 at 3:10
  • but this escape won't work in python... Why do you think that? Commented Jul 12, 2019 at 3:10
  • @user2357112 it is not? it did print \" instead of " on mine Commented Jul 12, 2019 at 3:12
  • wait, it did, but I meant r"\"", can I do this with raw string? Commented Jul 12, 2019 at 3:13
  • 2
    @StephenRauch: That's not really a raw string, though. It's implicitly concatenating r"", '"', and "". Commented Jul 12, 2019 at 3:16

2 Answers 2

1

you can perhaps use a triple quoted string

print("""I wasn't, I shan't. "This is a quote".""")

your output should be

I wasn't, I shan't. "This is a quote".

Sign up to request clarification or add additional context in comments.

Comments

0

If you cannot use ' and must use raw strings, then there is no way to express a single double quotation mark " as a string.

There are two methods of including a string delimiter (' or ") in a string:

  1. Use the other delimiter for the string, e.g. '"' or "'"
  2. Escape the character with a backslash, e.g. "\"" or '\''

Your constraints remove both of those possibilities.

1 Comment

@Recessive huh? r""" " """ is not '"', yours has a space on either side.

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.