程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python string preceded by u, R, B

編輯:Python

1. u/U: Express unicode character string

Not just for Chinese , For any string , Represents a string that is unicode code .
General English characters in the use of a variety of encoding , Basically, it can be parsed normally , So I don't usually bring it u; But Chinese , The required code must be indicated , Otherwise, once the code is converted, there will be garbled code .
It is recommended that all coding methods adopt utf8 code .

2. r/R: The original string that is not escaped raw string

Ordinary characters are added \ May be used by the compiler as escape characters , For example, the most common ”\n” Means line break ,”\t” Express Tab etc. , Such a string may not express what we want . And if so r start , Then explain the following characters , They are all ordinary characters , That is, if it is “\n”, Add... To the front r after , It becomes a string r"\n" that " " The string in represents the original meaning , namely A backslash character , A letter n, Not a line break .
With r Start character , Often used in regular expressions , Corresponding re modular .

3. b:bytes

python3.x Default in str yes (py2.x Inside )unicode, bytes yes (py2.x) Of str, "b" The prefix stands for bytes
python2.x in , b Prefixes don't make any sense , Just for compatibility python3.x This way of writing


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved