Alex Vincent
Alex Vincent

Reputation: 97

Printing a string of text using double quotes

print(''What is "program"?'')

I'm required to use double quotations either 2 apostrophes ('') or 2 quotation marks ("") to print this string, but the quotes on program creates a syntax error. I tried using backslash before the " to ignore them, but that doesn't work either

Upvotes: 0

Views: 5935

Answers (3)

Rajib Kumar Dey
Rajib Kumar Dey

Reputation: 71

Using Triple Quote is the most easiest way without remembering where to put extra / Try This:

print('''What is "program"?''')

Upvotes: 0

Chris
Chris

Reputation: 22953

You have two options for printing double quotes in Python.

  • You can use the escape character(\) to escape the double quotes, telling Python that they are not "special":

    print("What is the \"program\"")
    
  • Or you can take advantage of the fact that single quoted strings can contain double quotes and their is no need to escape them:

    print('What is the "program"')
    

Upvotes: 5

McNets
McNets

Reputation: 10807

Try this:

print("What is \"program\"?")

Upvotes: 3

Related Questions