The meaning of python before the character u.j.r.f, etc.
1. Precede the string with u
I am a string consisting of Chinese characters. "
Function:
The latter string is encoded in Unicode format, which is generally used in front of the Chinese string to prevent garbled code when it is used again because of the storage format problem of the source code.
2. Precede the string with r
Example: r "\ n\ n" # means a normal new string\ n\ n, not a new line.
Function:
Remove the transfer mechanism of the backslash.
(special characters: those with a backslash plus corresponding letters to indicate the corresponding special meaning, such as the most common "\ n" for line break, "\ t" for Tab, etc. )
Application:
It is often used for regular expressions, corresponding to re modules.
3. Precede the string with b
Example: response = b'Hello wordholders'# b''indicates that this is a bytes object
Function:
The b "" prefix indicates that the following string is of type bytes.
Use:
In network programming, servers and browsers recognize only bytes type data.
For example, the parameters of the send function and the return value of the recv function are of type bytes.
Attached:
In Python3, the way bytes and str convert each other is
Str.encode ('utf-8') bytes.decode (' utf-8')
4. Precede the string with f
Import timet0 = time.time () time.sleep (1) name = 'processing'# begins with f to indicate that the python expression print (f' {name} done in {time.time ()-t0pur.2f} s') in braces is supported within the string output: processing done in 1.00s