Joining a list of python objects with __str__ method

前端 未结 5 777
孤城傲影
孤城傲影 2021-01-02 09:44

I\'ve already looked at this question on representing strings in Python but my question is slightly different.

Here\'s the code:

>>> class W         


        
5条回答
  •  渐次进展
    2021-01-02 09:50

    "...it would be nice to avoid doing that every time..."

    You want to avoid repeating that same code multiple times? Then use a function;:

    def join_as_str(alist):
        return "\n".join(str(item) for item in alist)
    

提交回复
热议问题