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

Source: Internet
Author: User
In Python, strings can be enclosed in single quotes or double quotes, which are equivalent, while in PHP, some of the single and double quotes are not the same, although the expression of the string, but in PHP single quotation mark resolution faster than double quotation marks.
If you need to represent a string object in Python, there is no difference between single and double quotes.
Vice versa. That's why Python is allowed in two ways. In practice, Python single quotation marks and Python double quotes are used more, there are two ways to express, you do not have to use the old escape character.
In Python, for example:
A = ' I love \ ' Laowang python\ '
Print a
And
A = "I love ' Laowang python '"
The result of print a is the same.
The Python three-quotes form is used to enter multiple lines of text, that is, the content entered between the three quotation marks will be preserved, the number and double quotation marks are not escaped, in which the invisible characters such as \ n and \ t will be preserved, the advantage is that you can replace some of the multiple lines of text.
Like what:
Content = "' wwwfefefefefse% (name) s is
Haha,he Age was% (age) s ' '
c = content% {' name ': ' Pythoner ', ' age ': ' 20 '}
The result of print C is:
Wwwfefefefefsepythoner is
Haha,he Age is 20
  • 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.