Python string handling

Source: Internet
Author: User
Tags escape quotes

1. Single-quote strings and escape quotes

Single and double quotation marks do not make much difference, and a backslash (\) can be used to escape the quotation marks in a string for the special symbol that appears.

2. Stitching strings

  

3. String representation, str and repr (two mechanisms for converting a value to a string)

3.1, Str converts the value into a reasonable form of the string for the user to understand;

3.2. Repr creates a string that represents a value in the form of a valid Python expression, repr (x) can be represented by ' X ' (single quotes), but is no longer used in pyhton3.0, so it is recommended to use REPR

  

4. Comparison of input and raw_input

The 4.1 input function assumes that the user entered a valid Python expression, and if the user enters a string, it must be quoted

The 4.2 raw_input function will take all the input as the original data, and then put it into the string, so if you enter a number then use input, otherwise you should use the Raw_input

  

5. Long strings, raw strings, and Unicode

5.1 Long strings, use three quotation marks "" or "" "for strings that span multiple lines

5.2 Original string, string starting with R, each character entered in the original string will be consistent with the way it is written

Ordinary strings in 5.3 Python are stored internally in 8-bit ASCII format, while Unicode strings are stored as 16-bit Unicode characters, which can represent more character sets, such as Chinese

Python string handling

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.