-2

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?

Radia
  • 3
  • 3
  • What do you mean? that is the method signature of the `str.find`method. – Jan May 10 '20 at 07:07
  • @Jan I want to know what does that mean `[,` in S.find(sub[, start[, end]]) – Radia May 10 '20 at 07:19
  • 1
    Have you considered looking in the actual [docs](https://docs.python.org/3/library/stdtypes.html#str.find)? "*__Optional arguments__ start and end are interpreted as in slice notation*". BTW, the square brackets usually are a way of saying that something is optional. – Tomerikoo May 10 '20 at 07:28
  • The method's signature (and its complete docstring) is shown and explained here for example: [https://docs.python.org/3/library/stdtypes.html#str.find](https://docs.python.org/3/library/stdtypes.html#str.find) – Jan May 10 '20 at 07:28
  • @Tomerikoo sorry, my apologies. I should have checked the docs. but thank you for your comment – Radia May 10 '20 at 07:42

1 Answers1

1

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.

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Jackson
  • 1,213
  • 1
  • 4
  • 14