The difference between single quotes, double quotes, and three quotes in Python

Source: Internet
Author: User


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,\
S2 and S1 are the same. If you use 3 double quotes, you can go straight

The answer is as follows:
S3 = "" "Hello,
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.