What is used to represent Strings in Python.Is double quotes used for String representation or single quotes used for String representation in Python?

Questions by RyanJames   answers by RyanJames

Showing Answers 1 - 10 of 10 Answers

Santosh Malvi

  • Apr 9th, 2007

  • Using Single Quotes (')

    You can specify strings using single quotes such as 'Quote me on this' . All white space i.e. spaces and tabs are preserved as-is.

  • Using Double Quotes (")

    Strings in double quotes work exactly the same way as strings in single quotes. An example is "What's your name?"

  • Using Triple Quotes (''' or """)

    You can specify multi-line strings using triple quotes. You can use single quotes and double quotes freely within the triple quotes. An example is

    '''This is a multi-line string. This is the first line.
    This is the second line.
    "What's your name?," I asked.
    He said "Bond, James Bond."


  • Jun 13th, 2011

You can use single quote, double quote or triple quotes to represent strings. Triple quotes could use 3 consecutive single quotes or 3 consecutive double quotes to enclose a string.

For example, all the four string representations given below are the same.

" Double quote representation" 
'Single quote representation'
"""Triple quote representation"""
'''Triple quote representation'''

But choosing any of these quotes to represent a string depends upon the context.

For example,

"Harsha's father works with the state Government" 

In the above statement, you can not replace the double quote with a single quote to represent the string since the string itself contains a single quote.  But a triple quote in place of the double quote works fine. In the similar way, we can combine single and double quotes in case of string representations. Another example given below.

'Single quotes mixed with "double quotes" here'

But a triple quote is actually used when a string spans over multiple lines. 

For example, 

'''Triple quotes allow
to write a statement in 
multiple lines without using the new line character'''

  Was this answer useful?  Yes

Joseph E. Martinez

  • Oct 13th, 2011


  Was this answer useful?  Yes


  • Apr 29th, 2013

In python both single quote and double quotes are valid for string representation and also we can use triple quote for multiline string representation.

  Was this answer useful?  Yes


  • Sep 10th, 2014

Single quotes for represents a Character
double quotes represents a word or sentence
triple quotes represents a paragraph.

  Was this answer useful?  Yes

Agrim Sharma

  • Dec 11th, 2014


We can use both of them for string. But the best way is to use double quotes as we can input " s " of any character.

  Was this answer useful?  Yes

dhanya kumar

  • Jan 12th, 2015

most preferable way by PEP 8 is in double quotes

  Was this answer useful?  Yes

Ravindra Kumar Singh

  • Jul 6th, 2017

Both works in Python

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.


Related Answered Questions


Related Open Questions