Get the App
SLTechnology News&Howtos  ›  Development  › 

Python finds out what the computing functions are

Shulou Source: shulou.com Published: 2022-06-03 17:41:41 10月01日 Update

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.

Tags: Index character output article function between right multiple more different good practical same subscript position content then function letter string Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Docker Shulou Information Redmi Shulou Tech Info