파이썬 Python string.join(list) on object array rather than string array
Python에서는 다음을 수행 할 수 있습니다. >>> list = ['a', 'b', 'c'] >>> ', '.join(list) 'a, b, c' 객체 목록이있을 때 쉽게 똑같이 할 수있는 방법이 있습니까? >>> class Obj: ... def __str__(self): ... return 'name' ... >>> list = [Obj(), Obj(), Obj()] >>> ', '.join(list) Traceback (most recent call last): File "", line 1, in TypeError: sequence item 0: expected string, instance found 아니면 for 루프를 사용해야합니까? 해결 방법 대신 목록 이해 또는 생성기 표현식을 사용할 ..
2020. 10. 12.