Single quotation marks, double quotation marks, multiple quotation marks, and double quotation marks in python

Source: Internet
Author: User

Single quotation marks, double quotation marks, multiple quotation marks, and double quotation marks in python

First, the difference between double quotation marks (1) and three double quotation marks (3). Strings represented by double quotation marks are usually written as one line.
For example:
S1 = "hello, world"
If you want to write multiple lines, you need to use the \ ("hyphen"), as shown in
S2 = "hello ,\
S2 is the same as s1. If you use three double quotes, you can write them directly, as shown below:
S3 = "" hello,
Hahaha. "", so s3 is actually "hello, \ nworld, \ nhahaha.", pay attention to "\ n", so,
If you have many \ n strings and you do not want to use \ n in the strings, you can use three pairs.
Quotation marks. 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 ."""
This is the difference between three double quotes and one double quotation mark. The difference between the three double quotes and one single quotation mark is also
It is the same as this. In fact, there is a reason why python supports single quotes. Below I will compare one single quotes and
The difference between one double quotation mark.

When I use single quotes to represent a string, to represent the string Let's go, it must be like this:
S4 = 'let \'s go '. Note that no, there is a' in the string, and the string is expressed with ', so
At this time, we need to use the Escape Character \ (\, the escape character should be known), if your string contains a lot
It looks uncomfortable. python also solves this problem well, as shown below:
S5 = "Let's go"
At this time, we can see that python knows that you use "to represent the string, so python will put
Single quotation marks (') are processed as common characters. Is it very easy.
The same applies to double quotation marks. The following is an example.
S6 = 'I realy like "python "! '

This is why single quotes and double quotes can both represent strings.


In python, double quotation marks are single quotes and three quotation marks. What is the difference? There is no difference. It is just a character.

1. single quotation marks and double quotation marks are used in the same way, but if the character string contains the same characters, use \ for escape.

1) print 'hello'
2) print "hello"
1 and 2. The result is hello.

3) print 'hell \ 'O'
4) print "hell 'o"
3 and 4, the result is hell 'o

5) print 'hell "o'
6) print "hell \" o"
5 and 6, the result is hell "o

2. the three quotation marks are different from each other: "What you see is what you get". For an html or xml string, use the three quotation marks to make it straight (in this case, use single quotation marks or double quotation marks to escape)
For example:
Print '''
The result is

What are the differences between single quotes and double quotes in java?

The data quoted in single quotes is of the char type.
Double quotation marks are String-type data.
Single quotes can only start with one character
The double quotation marks can lead to 0 or more
The single quotes can be replaced with double quotes.
The append method is an override method, which can include both char and String data, and other types.
We recommend that you take a look at the StringBuffer api method.

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.