Get the App
SLTechnology News&Howtos  ›  Development  › 

How does python extract the specified contents of a string

Shulou Source: shulou.com Published: 2022-05-31 17:50:50 09月29日 Update

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.

Tags: Content characters strings data methods types only knowledge delimiters variables articles indexes values examples easy to operate tutorials articles easy to understand more environment Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Microsoft macOS Linux vpn