[Python] [Small knowledge] Python string with u, r, b meaning

Source: Internet
Author: User
1, string before plus u

Example: U "I am a string that contains Chinese characters. "

Function: The following string is encoded in Unicode format, generally used in front of the Chinese string, to prevent the source code storage format problems, resulting in re-use garbled.

PS: Not just for Chinese, you can target any string, and the representation is on the string. General English characters in the use of various codes, the basic can be parsed normally, so generally without u. But there are problems in Chinese, it is necessary to think before the school on the machine to tap the code when the same, a plug, a copy of the source code, a open, the Chinese part of the whole box garbled ... The thief was embarrassed ...

2. Add r before string

Example: R "\n\n\n\n\n\n"

Function: The string following the declaration is a normal string, relative, special string contains: The escape character \ t what.

Test results:

  

Usage: Generally used in regular expressions, file absolute address, etc...

3, string before plus B

Function: The default str in python3.x is (py2.x) Unicode, Bytes is (py2.x) str, b "" prefix represents bytes
python2.x, the B prefix is nothing specific, just to be compatible with python3.x.

4, after the statement:

Reference: http://blog.csdn.net/u010496169/article/details/70045895

Reprint please indicate the source ('? ') ): http://www.cnblogs.com/Twobox/

2017-08-22 23:45:36

[Python] [Small knowledge] Python string with u, r, b meaning

Related Article

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.