Using quotation marks inside quotation marks

You need to escape it. (Using Python 3 print function):

>>> print("The boy said \"Hello!\" to the girl")
The boy said "Hello!" to the girl
>>> print('Her name\'s Jenny.')
Her name's Jenny.

See the python page for string literals.


You could do this in one of three ways:

  1. Use single and double quotes together:

    print('"A word that needs quotation marks"')
    "A word that needs quotation marks"
    
  2. Escape the double quotes within the string:

    print("\"A word that needs quotation marks\"")
    "A word that needs quotation marks" 
    
  3. Use triple-quoted strings:

    print(""" "A word that needs quotation marks" """)
    "A word that needs quotation marks" 
    

Python accepts both " and ' as quote marks, so you could do this as:

>>> print '"A word that needs quotation marks"'
"A word that needs quotation marks"

Alternatively, just escape the inner "s

>>> print "\"A word that needs quotation marks\""
"A word that needs quotation marks"