Original Translation
57
There are two common arguments against this usage.
58
The first runs along the lines of: "It looks really ugly using a method of a string literal (string constant)", to which the answer is that it might, but a string literal is just a fixed value. If the methods are to be allowed on names bound to strings there is no logical reason to make them unavailable on literals.
59
The second objection is typically cast as: "I am really telling a sequence to join its members together with a string constant". Sadly, you aren't. For some reason there seems to be much less difficulty with having :meth:`~str.split` as a string method, since in that case it is easy to see that ::
60
"1, 2, 4, 8, 16".split(", ")
61
is an instruction to a string literal to return the substrings delimited by the given separator (or, by default, arbitrary runs of white space).
62
:meth:`~str.join` is a string method because in using it you are telling the separator string to iterate over a sequence of strings and insert itself between adjacent elements. This method can be used with any argument which obeys the rules for sequence objects, including any new classes you might define yourself. Similar methods exist for bytes and bytearray objects.
63
How fast are exceptions?
64
A try/except block is extremely efficient. Actually catching an exception is expensive. In versions of Python prior to 2.0 it was common to use this idiom::
65
try: value = mydict[key] except KeyError: mydict[key] = getvalue(key) value = mydict[key]
66
This only made sense when you expected the dict to have the key almost all the time. If that wasn't the case, you coded it like this::