-2

Why does the Python console returns single quotes for string literals for all types of quote delimeters?

>> '1'
'1'
>> "1"
'1'
>>"""1"""
'1'
Djangonow
  • 413
  • 1
  • 4
  • 9
  • 6
    string literals are *source code*, they all produce *string objects*, which have no knowledge of the literal that produced them (why would they?) – juanpa.arrivillaga Aug 03 '20 at 10:59
  • 1
    Does this answer your question? [Single quotes vs. double quotes in Python](https://stackoverflow.com/questions/56011/single-quotes-vs-double-quotes-in-python) – L.Grozinger Aug 03 '20 at 11:01
  • For the same reason that -0 is 0 - `"1"` and `'1'` are the same string, and 0 and -0 are the same number. – kaya3 Aug 03 '20 at 11:01
  • no I'm not asking single vs double quotes, I'm asking why they all return single quotes. – Djangonow Aug 03 '20 at 11:04
  • 1
    The string doesn't know or remember how you wrote it in the first place, any more than the number 0 remembers whether you gave it a minus sign. It is just a value. – kaya3 Aug 03 '20 at 11:05
  • @kaya3 although floats have signed 0's – juanpa.arrivillaga Aug 03 '20 at 11:09
  • 1
    @Djangonow **because there are no single or double quotes, or triple quotes in the string**. The string objects is defined by the *characters* (rather, unicode code points) it contains. What type of string literal that is used in the source code to create it isn't information that the object has, or should have. – juanpa.arrivillaga Aug 03 '20 at 11:10

1 Answers1

0

Python makes it convenient for itself to handle objects in a simple manner. If you really need an explicit way of memorizing quotes use literal quote characters.

>>> "\"\"Look, I'm around two qoutes!!!\"\""
'""Look, I\'m around two double qoutes!!!""'
peki
  • 669
  • 7
  • 24