Search code examples
python-3.xdocstring

What does S.find(sub[, start[, end]]) mean?


I'm learning to use python docstring.

>>> print(str.find.__doc__)
S.find(sub[, start[, end]]) -> int
...

When I print str.find() docstring, I don't understand what this means.

What does S.find(sub[, start[, end]]) mean?


Solution

  • It means that the method find in String will take in 3 parameters of which 2 are optional.

    Example:

     a = "Hello World"
     a.find("World")        # returns 6
     a.find("World", 4)     # returns 6
     a.find("World", 4, 6)  # returns -1 meaning it cannot be found
    

    Back to your output:

    S.find(sub[, start[, end]]) -> int
    
    • S here refers to the String variable which in my case was a.

    • -> int means the function outputs an integer which is by default the position of the found word or -1 if not found which in my case was 6 and -1.

    • sub refers to the word you are looking for which in my case was "World".

    • start and end refer to the start and end indices as to where to find the string which in my case was 4 and 6 respectively.