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

前端 未结 9 789
醉梦人生
醉梦人生 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:42

    From server side, if we send any response, it will be sent in the form of byte type, so it will appear in the client as b'Response from server'

    In order get rid of b'....' simply use below code:

    Server file:

    stri="Response from server"    
    c.send(stri.encode())
    

    Client file:

    print(s.recv(1024).decode())
    

    then it will print Response from server

提交回复
热议问题