首页 > 代码库 > String methods
String methods
A method is similar to a function – it takes arguments and returns a value – but the syntax is different. For example, the method upper takes a string and return a new string with all uppercase letters. Instead of the function syntax upper(text), it uses the method syntax text.upper().
This form of dot notation specifies the name of the method, upper, and the name of the string to apply the method to, text. The parentheses indicate that this method has no parameters.
A method call is called an invocation; in this case, we would say that we are invoking upper on the word.
As it turns out, there is a string method named find that is remarkably similar to the function we wrote. Actually, the find method is more general than our function: it can find substrings, not just characters:
It can take as a second argument the index where it should, and the third argument the index where it should end:
from Thinking in Python