Python string processing, python string

Source: Internet
Author: User

Python string processing, python string

1. Single quotes string and escape quotes

Single quotation marks are not much different from double quotation marks. special symbols can be escaped by backslash.

2. concatenate strings

3. String representation, str and repr (two mechanisms for converting values into strings)

3.1 str converts the value to a string in a reasonable form for your understanding;

3.2. repr creates a string that represents the value in a valid python expression. repr (x) can be expressed as 'X' (single quotes, however, in pyhton3.0, ''is no longer used, so we recommend that you use repr.

4. Comparison of input and raw_input

4.1 The input function assumes that the user inputs a valid Python expression. If the user inputs a string, it must be enclosed in quotation marks.

4.2 The raw_input function treats all input data as the original data and puts it into the string. Therefore, if the input is a number, input is used; otherwise, raw_input is used.

5. Long String, original string, and Unicode

5.1 long string. For strings that need to span multiple lines, use three quotation marks ''' or """"""

5.2 original string. The string starts with r. Each character entered in the original string is consistent with the writing method.

5.3 The common character strings in Python are stored in an internal 8-bit ASCII code format, while the Unicode character strings are stored as 16-bit Unicode characters, which can represent more character sets, such as Chinese

 

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.