String [find] method

x.find()-----Check whether there is a certain character in the string, and return the index, if the query result has multiple identical characters, execute and display the index corresponding to the first character from left to right

Multiple identical characters only return the index of the first character from left to right

If you want to find other same characters, you can find them by slice

x.rfind()------Find a character from the right and return the corresponding index

x.index()--------Find the index of the string, return the index if there is any, and report an error if there is no. This is different from the x.find() method. It is more convenient to use find in the program because there is no need to deal with error reporting Condition

x.count()--------counts the number of occurrences of a character

x.split()--------Use a certain character to split a string into multiple elements "By default, spaces are used to split, and by default the entire string is split from left to right, and it can also be split according to Selected division area"

Some characters in the string can be used as the segmentation. The following figure uses the character "a" to segment the execution results

By default, the entire string is split, and the split region can also be selected according to the situation

The picture shows a maximum of 2 splits from left to right

x.rsplit()--------String is split from right to left according to conditions

x.splitlines()-----Split the string into multiple elements by line breaks

x.removeprefix()-------Remove some prefixes from the string

x.removesuffix()--------Remove some suffixes from the string

x.replace()---------Replace the specified character with the target character

The picture below shows replacing all "a" with "A"

Guess you like

Origin blog.csdn.net/qq_42954795/article/details/127422757