Python Beginners Learn the basics of data types--string types

Source: Internet
Author: User

A string in Python is defined as a set of characters between quotation marks, which can be enclosed in ' (a pair of single quotes) or "(a pair of double quotation marks), or by" "" (a pair of three double quotes) or ' ' (a pair of three single quotes). Use the index operator ([]) and the Slice operator ([:]) to get substrings. In Python, the index of the first character of a string is 0, and the last character's index is-1. The indexes and slices are explained in a later article.

Let's start by creating the following string! For example:

str1 = ' Maya ' srt2 = ' coder '

strings can also be calculated!

Strings can be concatenated with + or duplicated with the * operator. Let's look at an example:

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M00/85/AA/wKiom1er27jyABgsAABWMAtW7jo158.png-wh_500x0-wm_3 -wmp_4-s_3109346880.png "title=" 11.png "alt=" Wkiom1er27jyabgsaabwmatw7jo158.png-wh_50 "/>

Use of string escape characters

String many times need to break the line, enter the operation, the page break and other special symbols, this time need to use the escape \ Symbol, commonly used escape symbols, such as:

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M00/85/A9/wKioL1er28Sj-6f1AABTU_efbug631.png-wh_500x0-wm_3 -wmp_4-s_3537525234.png "title=" 12.png "alt=" Wkiol1er28sj-6f1aabtu_efbug631.png-wh_50 "/>

In addition to the use of the transfer, we can actually use "" "(three double quotes) or" (three single quotation marks) (this is actually mentioned in the python quotation marks when we mention it), so that the escape character such as line break does not need to escape, they are included in the string.

If we use R or R in front of the string to define the string, the transfer character will fail. (The last character of the string defined by Ps:r cannot be \, otherwise it will be an error.) Let's see what happens:

More content learning experience, just in Http://www.mayacoder.com/lesson/index

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/85/A9/wKioL1er29Oh_1-qAAC6VvHRosE393.png-wh_500x0-wm_3 -wmp_4-s_2123686823.png "title=" 13.png "width=" 650 "height=" 765 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:650px; height:765px; "alt=" Wkiol1er29oh_1-qaac6vvhrose393.png-wh_50 "/>

Python Beginners Learn the basics of data types--string types

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.