Python strings usually have single quotes ('... '), Double quotation marks ("...") , Three quotation marks ("""...""") Or ("'..." '). A string enclosed by three quotation marks can be composed of multiple rows. Generally, the string can represent the narration string of a large segment. There is basically no difference in use, but double quotation marks and three quotation marks ("""...""") It can contain single quotes, three quotes ("'..." ') Can contain double quotation marks without escaping (including comments ).
Double quotes are used to avoid referencing English strings such as let's go (strings with single quotes)
A single quote is used to avoid referencing English strings such as I like "python" (strings with double quotes)
The string represented by a single-cited double-cited string is usually written as a line. If you want to write the line feed content, add \ n
Escape Special characters with (\), such (\),('),(")
A string in double quotation marks is usually written as a line.
For example:
S1 = "hello, world"
If you want to write multiple lines, you need to use the \ ("hyphen"), as shown in
S2 = "hello ,\
World"
S2 is the same as s1.
Three double quotes can be written directly, as shown below:
S3 = "" hello,
World,
Hahaha ."""
S3 is actually "hello, \ nworld, \ nhahaha. ", pay attention to" \ n ". Therefore, if you have many \ n strings and you do not want to use \ n in them, you can use three double quotes. You can also add comments to the string using three double quotes, as shown below:
S3 = "" hello, # hoho, this is hello, which can be annotated in a string of three double quotes.
World, # hoho, this is world
Hahaha ."""