Join함수는 아래와 같이 기술이 가능하다.
결합후 문자 = 결합문자.join(리스트)
실전 예를 보면 이해가 쉽습니다.
list = ['My', 'name', 'is', 'Kim', 'Test']
str = ' '.join(list)
print(str)
// My name is Kim Test
list = ['My', 'name', 'is', 'Kim', 'Test。', 15, "Years"]
str = ' '.join(list)
print(str)
// 숫자를 포함해서 하면 에러가 발생한다.
Traceback (most recent call last):
File "sample.py", line 2, in
str = ' '.join(list)
TypeError: sequence item 5: expected str instance, int found
list = ['My', 'name', 'is', 'Kim', 'Test。', 15, "Years"]
list = map(str, list)
str = ' '.join(list)
print(str)
'Python' 카테고리의 다른 글
For을 사용하는 방법 4가지 (0) | 2022.06.20 |
---|---|
python 가상환경(venv) (0) | 2021.10.17 |
conda command 정리 (0) | 2021.10.17 |
Anaconda install 하기 (0) | 2021.10.17 |
Python 와 Anaconda 의 차이점 (0) | 2021.10.17 |