python string前加b的原因

From:https://stackoverflow.com/questions/6269765/what-does-the-b-character-do-in-front-of-a-string-literal

 they produce an instance of the bytes type instead of the str type. 

 

  • str = '...' literals = a sequence of Unicode characters (UTF-16 or UTF-32, depending on how Python was compiled)
  • bytes = b'...' literals = a sequence of octets (integers between 0 and 255)

其实也可以加r:代表raw string,不会对转义符' \'进行转义。

你可能感兴趣的:(Python)