목록int (1)
컴공생의 다이어리
[파이썬, Python] int형 list join 적용 - TypeError: sequence item 0: expected str instance, int found
int형 list join 적용 int형 리스트를 join을 통해 합치려고 할때, 문자열 리스트를 join할때처럼 아래와 같이 한다면 TypeError: sequence item 0: expected str instance, int found라는 에러가 발생할 것이다. num = [1, 3, 5, 7] num_str = ", ".join(num)# 에러 발생 리스트 타입이 숫자인 경우에는 아래와 같이 map(str, 리스트이름)을 사용해서 리스트를 문자열로 합칠 수 있다. num = [1, 3, 5, 7] num_str = ", ".join(map(str,num)) # 1, 3, 5, 7 https://hyesun03.github.io/2017/04/08/python_int_join/ python int..
Development/Python & Django
2021. 9. 22. 00:01