Introduction to single, double, and triple quotes in Python

Source: Internet
Author: User
Tags comments in python


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 ."""

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: info-contact@alibabacloud.com 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.