When using (or not using) an escape backslash before a single quote when printing a plain string in Python,
print("\"Sari\'s here,\" I said.")
print("\"Sari's here,\" I said.")
both work as expected, producing
>>>"Sari's here," I said.
>>>"Sari's here," I said.
However, putting the same string into a container (list, tuple, or dictionary) and printing it causes some behavior that I don't understand.
print(["Sari's here, I said."])
print(["Sari\'s here, I said."])
print(["\"Sari's here,\" I said."])
print(["\"Sari\'s here,\" I said."])
print(["\"Sari\\'s here,\" I said."])
>>>["Sari's here, I said."]
>>>["Sari's here, I said."]
>>>['"Sari\'s here," I said.']
>>>['"Sari\'s here," I said.']
>>>['"Sari\\\'s here," I said.']
The backslash is printed before a single quote (whether I put it there or not) if I use an escape before a double quote. If I put two backslashes before the single quote, I get a third.
Can someone please help me to make sense of this? My original implementation was for height value in a dictionary (using a single and a double quote for feet and inches), when I discovered this strange behavior.
Please be kind. I'm learning the basics, but I'm eager.