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

Python finds out what the computing functions are

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

Share

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

This article will explain in detail what the python search calculation functions are, the editor thinks it is very practical, so share it for you to do a reference, I hope you can get something after reading this article.

1. Len calculates the number of characters in a string.

A Chinese character or a letter is a character.

Name ='I am aa\ n'#\ n as a newline character, calculate a character num = len (name) print (num) output: 5

2. Find retrieves the index / subscript position of the substring and retrieves the corresponding index starting from 0.

Returns-1 if it is not found.

# a.find () # find the corresponding index from 0 If there are more than one, look for the first msg from the left = 'The day is a sunny day'result1 = msg.find (' d') print (result1) result2 = msg.find. The first index print (result2) result3 = msg.find (from the fifth index to the ninth index (including 5 but not 9) # the first index print (result3) output of'd' is: 419-1

3. Rfind has the same function as find, except that it starts from the right to find the corresponding index.

# a.rfind () # start on the right to find the corresponding index msg = 'The day is a sunny day'result1 = msg.rfind (' d') result2 = msg.rfind ('da') # find multiple characters, it will return the index print (result1) print (result2) of the found' d': 19194, index/rindex returns the index of the desired value. Msg = 'The day is a sunny day'result = msg.index (' dd') print (result) output: Traceback (most recent call last): File "xxx.py", line 43, in result = msg.index ('dd') ValueError: substring not found's article on "what python finds computing functions" ends here. I hope the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good. Please 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