What does the 'b' character do in front of a string literal?

前端 未结 9 806
醉梦人生
醉梦人生 2020-11-21 05:07

Apparently, the following is the valid syntax:

my_string = b\'The string\'

I would like to know:

  1. What does this b
9条回答
  •  我寻月下人不归
    2020-11-21 05:30

    It turns it into a bytes literal (or str in 2.x), and is valid for 2.6+.

    The r prefix causes backslashes to be "uninterpreted" (not ignored, and the difference does matter).

提交回复
热议问题