Skip to content

Allow str.replace's 'count' to be a keyword argument #106487

Description

@hugovk

Feature or enhancement

Allow the count argument of str.replace to be a keyword to better describe its use.

Pitch

str.replace takes old and new strings as parameters, and an optional count parameter:

https://docs.python.org/3/library/stdtypes.html#str.replace

However, count cannot be a keyword argument:

>>> "aaa".replace("a", "b", 2)
'bba'
>>> "aaa".replace("a", "b", count=2)
TypeError: str.replace() takes no keyword arguments

It would be more explicit if the count parameter could also be a keyword, so there's no doubt about its meaning.

Previous discussion

Suggested by @treyhunner at https://mastodon.social/@treyhunner/110664375381530126

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13only security fixestype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions