Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-106318: Add example for str.rindex() method#143887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
vstinner merged 5 commits intopython:mainfromadorilson:106318.rindex
Feb 3, 2026
Merged
Changes fromall 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 deletionsDoc/library/stdtypes.rst
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand 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 forspam?

Copy link
ContributorAuthor

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 withstr.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
ContributorAuthor

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
ContributorAuthor

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
ContributorAuthor

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

[8]ページ先頭

©2009-2026 Movatter.jp