Python string before r, u, b

1, before the character string plus u

Example: u "I am a string containing Chinese characters."

Action: string behind encoded in Unicode format, generally used in front of the Chinese character string, to prevent the problem because the source storage format, resulting in garbled used again.

2, before the character string plus r

Example: r "\ n \ n \ n \ n" # represents a normal green string \ n \ n \ n \ n, not represented for the trip.

Role: remove the backslash escape mechanism. (Special characters: those that, together with the corresponding letter backslash, represents the corresponding special meaning, such as the most common "\ n" newline, "\ t" represents the Tab and so on.)

Application: commonly used in the regular expression, corresponding to re module.

3, before the character string plus b

Example: response = '! </ H1> <h1> Hello World' b # b '' indicates that this is a target bytes

Action: b "" prefix: string back type is bytes.

Use: network programming, servers and browsers only recognize the type of data bytes.

Such as: recv send function parameters and return values ​​are a function of the type of bytes

PS: In Python3 in bytes and another conversion method is str

str.encode('utf-8')
bytes.decode('utf-8')

Guess you like

Origin www.cnblogs.com/leadership/p/11697661.html