Python original string and Unicode string operator usage Example Analysis, pythonunicode
This document describes the usage of the original Python string and Unicode string operators. We will share this with you for your reference. The details are as follows:
# Coding = utf8''' in the original string, all strings are used directly in the literal sense without escaping special or printable characters. Regular Expressions are strings that warn you about the matching method. They are composed of special characters, including characters, groups, matching information, variable names, and character classes. Before the original string is enclosed by the first quotation mark, you must add the r or R letter to indicate that the character is the original string. The original string and common string have almost identical syntax. Unicode string operator. uppercase and lowercase U are introduced together with Unicode strings in Python1.6. It is used to convert a standard string or a string containing Unicode characters into a full Unicode String object. The string method and Regular Expression Engine also support Unicode. The Unicode operator can also accept the original Unicode string, as long as the Unicode operator and the original string operator are connected together. Note: The Unicode operator must appear before the original string operator. '''Import re # original operator function def originalOper (): # It is not the original character to indicate the line break print "\ n" # It is the original character to indicate \ n print r "\ n" try: # add r to the file path without escaping \ # in the file path, it indicates the diagonal line testFile = open (r "E: \ PythonDemo \ CorePythonBook2 \ output", "r ") for line in testFile. readlines (): # format strings # Use repr () first () convert the function to the original character line = "% r" % line # add r to the matching mode # convert the matched character to the original character m = re. search (r "\ [rn]", line) # Whether the string contains matching characters # if the string contains output if m is not None: print line character t Exception, e: print e f Inally: testFile. close () # Unicode operator function def unicode=(): print u "abc" print u "\ u1234" print u "abc \ u1234 \ n" print ur "Hello \ nWorld! "# Call function # output operation original character result originalOper () # output Unicode string unicode= ()
The running result is as follows:
PS: Here are some Unicode conversion tools for your reference:
Online Unicode/Chinese Conversion Tool:
Http://tools.jb51.net/transcoding/unicode_chinese
Native/Unicode online encoding conversion tool:
Http://tools.jb51.net/transcoding/native2unicode
Tools for online conversion between Chinese characters, ASCII codes, and Unicode codes:
Http://tools.jb51.net/transcoding/chinese2unicode