Http://blog.sina.com.cn/s/blog_6be8928401017lwy.html
First, the difference between 1 double quotation marks and 3 double quotes, the words represented by double quotation marks
Strings are usually written in a line
Such as:
S1 = "Hello,world"
If you want to write multiple lines, then use \ ("line character"),
Such as
S2 = "hello,\
World
S2 and S1 are the same. If you use 3 double quotes, you can go straight
The answer is as follows:
S3 = "" "Hello,
World
hahaha. "", then S3 actually
Is "Hello,\nworld,\nhahaha.", note "\ n", so,
If you have a lot of strings, you don't want to be in a string. \ n
, then you can use 3 pairs of
Quotes. and use 3 double quotes to add comments to the string.
As follows:
S3 = "" "Hello, #hoho, this is Hello, in 3 double-cited
Can have comments inside the string
World, #hoho
hahaha. "" "
This is the difference between 3 double quotes and 1 double quotation marks, 3
The difference between a double quote and a 1 single quotation mark is also
Is the same as this, actually Python supports single quotes for a reason
, let me compare 1 single quotes and
The difference between 1 double quotes.
When I use single quotation marks to represent a string, if I want to represent
Let's go this string, must be this:
S4 = ' let\ ' go ', note No, there is a ' in the string, and
Strings are used to represent, so
This is the time to use the escape character \ (\, the escape character should know
If you have a whole bunch of strings in your string
Escape character, looks sure to be uncomfortable, Python is also a good solution
This problem, as follows:
S5 = "Let ' s Go"
At this point, we see that Python knows that you are using "to represent strings,
So python just put that in the string
Single quotes ', as normal character processing, is not very simple
。
The same is true for double quotes, and here's an example
S6 = ' I realy like ' python '! '
That's why both single quotes and double quotes can represent strings.
The difference between single quotes, double quotes, and three quotes in Python