This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2015年04月24日 05:49 by Elizacat, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Messages (3) | |||
|---|---|---|---|
| msg241912 - (view) | Author: Elizabeth Myers (Elizacat) * | Date: 2015年04月24日 05:49 | |
str.startswith and str.endswith should accept multiple arguments when passing in strings. This makes it easier to check if the first character of a string is one of a given option, versus this awkward construction: >>> f = 'abc' >>> 'test'.startswith(tuple(f)) False With my proposal, this could be shortened to 'test'.startswith(*f) for easy testing. This also makes it easier to check if a string begins with one of any combination of matches. |
|||
| msg241915 - (view) | Author: Ethan Furman (ethan.furman) * (Python committer) | Date: 2015年04月24日 06:03 | |
We can already do
--> some_string.starts_with(('innie','minnie', 'minie', 'moe'))
Your proposal appears to be equivalent to:
--> 'test'.startswith(('a', 'b', 'c'))
How often do you check to see if a string starts with only a single character?
-1
tuple() is the correct solution to this problem.
|
|||
| msg241918 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2015年04月24日 07:09 | |
This proposition conflicts with optional parameters of str.startswith().
>>> 'test'.startswith(('a', 'b', 'c'), 1, 3)
False
|
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:16 | admin | set | github: 68235 |
| 2015年04月24日 07:09:58 | serhiy.storchaka | set | status: open -> closed nosy: + serhiy.storchaka messages: + msg241918 resolution: rejected stage: resolved |
| 2015年04月24日 06:03:42 | ethan.furman | set | nosy:
+ ethan.furman messages: + msg241915 |
| 2015年04月24日 05:49:07 | Elizacat | create | |