-2

How can I print this ('''""") in Python?

I tried this but I got error:

print("'''"""")

and I tried this but I got error:

print(""""""'''"""""")
2
  • The term you're searching for is "escaping". Read the Python documentation, how to escape a quote character in the middle of a string can be found there. Commented Jun 20, 2024 at 21:01
  • Welcome to SO! @Ulrich Eckhardt's comment should help you solve your problem, but my suggestions for future questions are: 1) use the formatting tools for your code (see meta.stackoverflow.com/questions/251361/…) 2) provide more information about the actual error messages you are seeing. Commented Jun 20, 2024 at 21:08

1 Answer 1

3

You can put a backslash character followed by a quote (\" or \').

This is called an escape sequence and Python will remove the backslash, and put just the quote in the string.

print("'''\"\"\"")
# or
print('\'\'\'"""')
Sign up to request clarification or add additional context in comments.

2 Comments

I rolled back to my edit because you don't need to escape both kinds of quotes in the string, and I wanted to demonstrate that you can use either kind of quotes for the string delimiters.
@wjandrea Yes, you are right, thank you very much for your help

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.