Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The meaning of python before the character u.j.r.f, etc.

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report