__str__
used only if the user of your object wants to turn it into a string, but str.join
not. You must explicitly convert your objects to values str
before you str.join
use them.
(Could str.join
str
, ? , .)
Python: " , ". str.join
, str
join
.
print(' '.join(str(x) for x in l))
join
str
, str
, A
str
.
class A(str):
def __new__(cls, text):
obj = super().__new__(cls, text)
return obj
l = [A('hello'), A('world')]
print(' '.join(l))
, .