What is the difference of declaring these strings in Python?

Asked

Viewed 75 times

3

Is there any difference between a string declared with single quotes '

a = 'Special cases aren\'t special enough to break the rules.'

and one with double quotes "

b = "Special cases aren't special enough to break the rules."

or even with multiple double quotes """

c = """Special cases aren't special enough to break the rules."""

or simple '''

d = '''Special cases aren't special enough to break the rules.'''

in Python? In a practical way, there seems to be no difference in these four expressions, see at Ideone.

Is there a difference? Are there cases where any of the options would be preferable? Why?

  • That’s a question that has an answer in English and was closed because it was considered "Not constructive".

  • 1

    If you don’t misread your question, why not also add to the question the strings defined with three single quotes and three double quotes? For example: a = """teste"""

  • 1

    I voted to reopen the question because I believe that the question marked as duplicate does not really answer the current question. The difference between char and string in Python and commented that both define a string, but nothing is said (nor is part of the scope of that question) about the differences between all statements of string.

  • @Andersoncarloswoss also believe not, +1 a vote to reopen.

  • 1
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.