Strings can be identified by single quotes ('...') or double quotes ("..."). \ can be used to escape quotes;
Case 1: If in the string has only single quotes but no double quotes, use double quotes, otherwise use single quotes Quote in quotation marks.
"yes",he said' ",he said >>>"\"yes\",he said "
Case 2: The character
with \ in front ofis regarded as What to do with special characters?
Add an r>>>print 'c:\some\name'c:\some ame
before the first quotation mark. In the example \n is treated as a newline symbol, then Add r before the first quotation mark: >>>print r'c:\some\name'c:\some\name
>>> print 'apple\nbanana'apple banana>>> print '''apple banana'''apple banana>>> print """apple banana"""apple banana>>>
Case 4: How to concatenate multiple strings in Together??
(1) You can use + (variable + string text is also applicable)>>> 'app' + 'le''apple'
(2) Adjacent ones are automatically connected together (Applicable when both are string literals)
>>> 'apple''love''banana''applelovebanana'>>>
>>> word = 'python'>>> word[0]'p'>>> word[1]'y'>>> word[-1]'n'>>> word[0:2]'py'>>> word[:2]+word[2:]'python'>>> len(word)6 >>>
Word[1] = 'a' This doesn't work!! !
For more Python learning (2)---Strings, please pay attention to the PHP Chinese website for related articles!