Skip to content
Merged
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
16 changes: 16 additions & 0 deletions Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2163,6 +2163,8 @@ expression support in the :mod:`re` module).

.. doctest::

>>> 'spam, spam, spam'.index('spam')
0
>>> 'spam, spam, spam'.index('eggs')
Traceback (most recent call last):
File "<python-input-0>", line 1, in <module>
Expand Down Expand Up @@ -2546,6 +2548,20 @@ expression support in the :mod:`re` module).

Like :meth:`rfind` but raises :exc:`ValueError` when the substring *sub* is not
found.
For example:

.. doctest::

>>> 'spam, spam, spam'.rindex('spam')
12
>>> 'spam, spam, spam'.rindex('eggs')
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a successful example, like looking for spam?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.

But I did it this way to be in line with str.index, which doesn't have a successful example.

Should I add it there as well?

Copy link
Member

Choose a reason for hiding this comment

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

But I did it this way to be in line with str.index, which doesn't have a successful example. Should I add it there as well?

Yes, I suggest to also add a successful example in str.index().

Try to use the same input string for both examples.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done here.

Copy link
Member

Choose a reason for hiding this comment

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

You didn't add a successful example to str.index().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a new PR: #144408

Copy link
Member

Choose a reason for hiding this comment

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

It doesn't deserve a whole new PR. Please change it in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All done.

Traceback (most recent call last):
File "<stdin-0>", line 1, in <module>
'spam, spam, spam'.rindex('eggs')
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
ValueError: substring not found

See also :meth:`index` and :meth:`find`.


.. method:: str.rjust(width, fillchar=' ', /)
Expand Down
Loading