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

How does python extract the specified contents of a string

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces python how to extract string specified content of the relevant knowledge, the content is detailed and easy to understand, simple and fast operation, has a certain reference value, I believe that everyone after reading this python how to extract string specified content article will have a harvest, let's take a look at it.

The operating environment of this tutorial: windows7 system, Python 3.9.1 Dell G3 computer.

1. Extraction method

(1) split is separated by delimiters.

(2) rsplit is separated by the last delimiter.

(3) convert to list list and delete a value.

(4) use the findall method in pre package.

(5) data return type of the findall method.

2. Examples

The data type returned by the findall method is a list, and the content of the list is only one, which is data of string type, so you can define a variable to receive it, and after receiving the variable, it becomes a list, and there is only one data of string type. Or define a list and first use the index to get the data, because there is only one data, so the index is at most 0.

Temp = [] Node1_temperature = re.findall (r'Node1_temperature: (. *) Node1_humidity', recv) temp.append (int (Node1_ character [0])), this is the end of the article on "how to extract string assignments from python". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to extract string specified content from python". If you want to learn more, you are welcome to follow the industry information channel.

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

Development

Wechat

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

12
Report