Defining strings in Python

Source: Internet
Author: User

Strings can be ‘‘ expressed in or "" enclosed. What if the string itself contains ? For example, if we want to represent  I‘m OK  a string, we can say it in " " parentheses:

"I ' m OK"

Similarly, if a string is contained " , we can use it as a ‘ ‘ means of enclosing:

' Learn ' Python "in Imooc '

What if the string contains and contains both " ?

At this point, you need to "escape" some special characters of the string , and the Python string is \ escaped.

To represent a stringBob said "I‘m OK".
Because ' and ' can cause ambiguity, so we insert a representation before it that \ this is an ordinary character and does not represent the beginning of the string, so the string can be represented as

' Bob said \ ' i\ ' m ok\ '. '

Note: the escape character \ does not count toward the contents of the string.

The usual escape characters are:

\ n indicates a newline \ t means a tab \ \ means \ character itself

The following two lines of text are printed in Python's string representation:

Python is started in 1989 by "Guido".

Python is free and easy to learn.

Reference:

s = ' Python was started in 1989 by \ ' Guido\ '. \npython are free and easy to learn. ' Print S



Defining strings in Python

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.