Third: base type-String type

Source: Internet
Author: User
Tags escape quotes

1) They can enclosed in a single quotes ( ‘...‘ ) or double quotes ( "..." ) with the same result. \ can is used to escape Quotes

2) If you don ' t want characters prefaced \ is interpreted as special characters, you can use raw strings By adding an r before the first quote

3) String literals can span multiple lines. One is using triple-quotes: """...""" or ‘‘‘...‘‘‘ . End of lines is automatically included in the string, but it's possible to prevent the for adding a at the \ end of T He line. The following example

4) Strings can concatenated (glued together) + with the operator, and repeated with*

5) Both or more string literals (i.e. the ones enclosed between quotes) next to all other is automatically concat Enated. This is only works with the literals though, not with variables or expressions.

6) Strings can indexed (subscripted), with the first character have index 0. There is no separate character type; A character is simply a string of size one.

7) Indices may also is negative numbers, to-start counting from the right. Note that since-0 is the same as 0, negative indices start from-1.

8) in addition to indexing,  slicing  is also supported. While indexing are used to obtain individual characters,  slicing  allows your to obtain substring. < /em> Note How the start was always included, and the end always excluded. this makes sure that s[:i] + S[i:] is always Equa l to s.  Slice indices has useful defaults; an omitted first index defaults to zero, an Omitted second index defaults to the size of the string being sliced.

9) Attempting to use a index that is too large would result in an error. However, out of range slice indexes is handled gracefully when used for slicing.

Python strings cannot be Changed-they is immutable. Therefore, assigning to a indexed position in the string results in an error.

One) the built-in function len() returns the length of a string

The above mentioned are the basic features of string, and the string itself is a class, so it has a lot of other methods, and many, the API address is as follows:

Https://docs.python.org/3/library/stdtypes.html#string-methods

Third: base type-String type

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.