Defining strings in Python

Source: Internet
Author: User
This article introduces you to the definition of a string in Python, a friend in need can refer to the content of the article


Defining strings in Python




> We've been explaining what a string is. Strings can be used " or "" is represented.

If the string itself contains ' What? For example we want to represent the string I ' m OK , at this point, you can use means:

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

this time, you need to " escape ", Python string with \ is escaped.

to represent the string bob said "I m OK".
because ' and ' can cause ambiguity, so we insert a \ Indicates that this is a normal character and does not represent the beginning of a string, so the string can be represented as a

' 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

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.