Strings can be identified by single quotation marks (' ... ') or double quotation marks ("...").
\ can be used to escape quotation marks;
Scenario One: If the string
single quotes without double quotes, quoted as double quotes, otherwise quoted in single quotation marks。
For example, to print:
Doesn ' t: >>> "doesn ' t"
"Yes", he said >>> ' yes ', he said '
Alternatively, use the escape symbol \
Doesn ' t: >>> ' doesn\ ' t '
"Yes", he said >>> "\" yes\ ", he said"
Scenario Two: What happens if the character preceded by \ is treated as a special character? Add an R before the first quotation mark
>>>print ' C:\some\name ' c:\someame
In the example, \ n is considered a newline symbol, then the first quotation mark is preceded by R:
>>>print R ' C:\some\name ' C:\some\name
Scenario Three: The string wants to be divided into multiple lines, how to do?? Use "" "..." "" or ' ... '
>>> print ' Apple\nbanana ' applebanana>>> print ' Applebanana ' applebanana>>> print ' "" Applebanana "" "Applebanana>>>
Scenario four: How to concatenate multiple strings together??
(1) can use + (variable + string text also applies)
>>> ' app ' + ' le ' apple '
(2) Adjacent automatic connection (for two all string literals)
>>> ' apple ' love ' banana ' applelovebanana ' >>>
Scenario Five: How does a string be intercepted (retrieved)? Use subscript
>>> word = ' python ' >>> word[0] ' P ' >>> word[1] ' y ' >>> word[-1] ' n ' >>> word[ 0:2] ' py ' >>> word[:2]+word[2:] ' python ' >>> len (word) 6>>>
Scenario Six: Want to change a character in a string, what to do??
WORD[1] = ' A ' This is not going to work!!!
Learn more about Python (ii)---string related articles please follow topic.alibabacloud.com!