Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1583,6 +1583,12 @@ expression support in the :mod:`re` module).
>>> 'Py' in 'Python'
True

If the substring *sub* is ``''``, then `:meth:~str.find` method will return
a value that is equal to ``len(str)``.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the text should explain why. As shows in the bpo-24243 ticket, people may be surprised by this behaviour if they don’t understand how it derives from Python’s notion of string slices. If you know that '' in 'abc' is true + the doc of str.find says it returns the highest index of the found substring, then this is not a surprise. I am not sure that mentioning len only here will help people make sense of it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notation note: let’s write code like len(s), not len(str).


>>> 'abc'.find('')
3


.. method:: str.format(*args, **kwargs)

Expand Down