Python str.join()
사용 버전: Python 3.6.8
사용 프로그램: Atom 1.36.1 x64
사용할 수 있는 '반복할 수 있는 것'으로는 '문자열', '리스트', '튜플', '딕션어리' 등이 있습니다.
str.join()은 문자열 사이에 또는 값들 사이에 원하는 문자를 넣어줍니다.
먼저 문자열의 경우입니다.


문자열 사이에 '.'이 들어간 것을 확인할 수 있습니다.
리스트의 경우입니다.


리스트의 경우 문자열과는 다르게, 값들 사이에만 '.'이 들어갑니다.
내용물이 str 형식이 아닌 경우, 오류가 발생합니다.
int, byte 형식은 오류를 일으키니 조심해야 합니다.


딕션어리의 경우입니다.


기본적으로 key 값이 join에 사용됩니다.
만약 value 값으로 join을 하고 싶다면, 다음과 같이 사용합니다.


딕션어리도 마찬가지로, str 형식이 아니면, 오류가 발생합니다.


끝.
사용 프로그램: Atom 1.36.1 x64
파이썬 str.join()에 대해서 알아보겠습니다.
괄호 안에는 반복할 수 있는 것들 중, 내용물이 문자인 것이 들어갑니다.사용할 수 있는 '반복할 수 있는 것'으로는 '문자열', '리스트', '튜플', '딕션어리' 등이 있습니다.
str.join()은 문자열 사이에 또는 값들 사이에 원하는 문자를 넣어줍니다.
먼저 문자열의 경우입니다.


문자열 사이에 '.'이 들어간 것을 확인할 수 있습니다.
리스트의 경우입니다.


리스트의 경우 문자열과는 다르게, 값들 사이에만 '.'이 들어갑니다.
내용물이 str 형식이 아닌 경우, 오류가 발생합니다.
int, byte 형식은 오류를 일으키니 조심해야 합니다.


딕션어리의 경우입니다.


기본적으로 key 값이 join에 사용됩니다.
만약 value 값으로 join을 하고 싶다면, 다음과 같이 사용합니다.


딕션어리도 마찬가지로, str 형식이 아니면, 오류가 발생합니다.


끝.
카테고리: Standard Library, Python
댓글
댓글 쓰기
궁금한 점은 댓글 달아주세요.
Comment if you have any questions.