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 operation method of searching and replacing Python string

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article will explain in detail the operation of searching and replacing Python strings. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Search and replace in Python string:

* S.find (substr, [start, [end]])

Returns the label of the * letter of substr in S, or-1 if there is no substr in S. The role of start and end is equivalent to searching in S [start: end]

* S.index (substr, [start, [end]])

Same as find (), except that a run-time error is returned when there is no substr in S

* S.rfind (substr, [start, [end]])

Returns the * letter label of the substr that appears in S, and returns-1 if there is no substr in S, that is, the first letter label of the substr that appears * times from the right.

* S.rindex (substr, [start, [end]])

* S.count (substr, [start, [end]]) # calculate substr in S

The number of occurrences

* S.replace (oldstr, newstr, [count])

Replace oldstar in S with newstr,count as the number of replacements. This is a general form of substitution, and there are some functions that replace special characters.

* S.strip ([chars])

To remove all the characters in the chars before and after S can be understood as replacing the chars before and after S with None.

* S.lstrip ([chars]) * S.rstrip ([chars]) * S.expandtabs ([tabsize])

Replace the tab characters in S with no spaces, and each tab is replaced with tabsize spaces, the default is 8. The above is a detailed introduction to the search and replacement in the Python string.

On the Python string search and replacement of the operation method to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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