How to print double quotes with the string variable in Python?

Printing double quotes with string variables can be tricky since double quotes are part of Python's string syntax. This article explores several methods to include double quotes in your printed output.

Common Mistakes

The following examples show what not to do when trying to print double quotes ?

print(" ")
print(" " " ")
print(""aString"")

The output of the above code is ?

  File "<string>", line 3
    print(""aString"")
          ^
SyntaxError: invalid syntax

Method 1: Using Single Quotes to Wrap Double Quotes

The simplest approach is to enclose double quotes within single quotes ?

print('Hello Tutorialspoint')
print('"Hello Tutorialspoint"')
Hello Tutorialspoint
"Hello Tutorialspoint"

Method 2: Using Escape Sequences

Use backslash " to escape double quotes within double-quoted strings ?

message = 'Hello Tutorialspoint'
print(""{}"".format(message))
print(f""{message}"")
"Hello Tutorialspoint"
"Hello Tutorialspoint"

Method 3: Using String Formatting with Variables

Multiple string formatting approaches can handle double quotes with variables ?

message = 'Hello Tutorialspoint'

# Using % formatting
print(""%s"" % message)

# Using .format() method
print('"{}"'.format(message))

# Using f-strings (Python 3.6+)
print(f'"{message}"')

# Using single quotes to wrap
print('"' + message + '"')
"Hello Tutorialspoint"
"Hello Tutorialspoint"
"Hello Tutorialspoint"
"Hello Tutorialspoint"

Method 4: Using Triple Quotes

Triple quotes allow both single and double quotes inside the string ?

message = 'Hello Tutorialspoint'
print(f'''"{message}"''')
print(f'"""{message}"""')
"Hello Tutorialspoint"
"""Hello Tutorialspoint"""

Comparison

Method Syntax Best For
Single quotes wrapper '"text"' Simple, readable
Escape sequences ""text"" Complex strings
f-strings f'"{var}"' Modern Python (3.6+)
Triple quotes f'''"{var}"''' Multi-line strings

Conclusion

Use single quotes to wrap double quotes for simple cases. For variables, f-strings with single quote wrappers provide the cleanest syntax. Escape sequences work well for complex formatting needs.

Updated on: 2026-03-15T17:41:59+05:30

14K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements