Q: Why have both
There are more ways to skin a cat :-)
It is great, we have at least one. dict
has it as method too, probably as it was convenient to
have it there.
Q: and which is better to use from a performance perspective?
Generally, you shall measure it (e.g. using timeit
) if you care. Do not expect big diferences.
Q: How to quickly figure out, if some task is a function or a method
... without looking at the documentation? hsplit is a function and not a method.
Is that really imporant? Just pick some of them, which serves you well enouhg.
Anyway, there is no general rule for naming functions and methods, which would help you.
If you need to learn anything more about variable, function or method in Python, learn using help
>>> help("a b".split)
Help on built-in function split:
split(...)
S.split([sep [,maxsplit]]) -> list of strings
Return a list of the words in the string S, using sep as the
delimiter string. If maxsplit is given, at most maxsplit
splits are done. If sep is not specified or is None, any
whitespace string is a separator and empty strings are removed
from the result.
>>> import string
>>> help(string.split)
Help on function split in module string:
split(s, sep=None, maxsplit=-1)
split(s [,sep [,maxsplit]]) -> list of strings
Return a list of the words in the string s, using sep as the
delimiter string. If maxsplit is given, splits at no more than
maxsplit places (resulting in at most maxsplit+1 words). If sep
is not specified or is None, any whitespace string is a separator.
(split and splitfields are synonymous)
In IPython console, this information is shown by using one or two question marks:
>>> "a b".split?