Issue 27017: Python3.5.1: type().startswith() - Python tracker (original) (raw)
Issue27017
Created on 2016-05-14 06:55 by VertigoRay, last changed 2022-04-11 14:58 by admin. This issue is now closed.
Messages (3) | ||
---|---|---|
msg265505 - (view) | Author: Ray (VertigoRay) | Date: 2016-05-14 06:55 |
This doesn't look like proper functionality Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> type('') <class 'str'> >>> type('').startswith('s') Traceback (most recent call last): File "", line 1, in TypeError: startswith() takes at least 1 argument (0 given) >>> type('').startswith('s', 's') True | ||
msg265506 - (view) | Author: SilentGhost (SilentGhost) * ![]() |
Date: 2016-05-14 07:08 |
This is exactly how methods on Python object have been behaving for year: any method can be called either as method on instance, or as method on class, with instance passed as the first argument. | ||
msg265508 - (view) | Author: Steven D'Aprano (steven.daprano) * ![]() |
Date: 2016-05-14 07:44 |
To explain in more detail: ``type('s').startswith`` is the same as ``str.startswith``, which is an unbound method in Python 2 and a regular function in Python 3. Either way, it expects *two* arguments: a string which becomes "self", and a second string argument, which is the prefix being tested for. So type('any string').startswith('alphabet', 'al') is a long way of writing 'alphabet'.startswith('al'). |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:58:31 | admin | set | github: 71204 |
2016-05-14 07:44:39 | steven.daprano | set | nosy: + steven.dapranomessages: + |
2016-05-14 07:08:56 | SilentGhost | set | status: open -> closed |
2016-05-14 07:08:20 | SilentGhost | set | nosy: + SilentGhostmessages: + resolution: not a bugstage: resolved |
2016-05-14 06:55:40 | VertigoRay | create |