결론부터 말씀드리면
split()은 빈 문자열은 죽이고 , split(" ")은 살립니다.
In conclusion, split() discards empty string, split(" ") do not
1
2
3
|
s=' abc bbb c d e '
print(s.split())
print(s.split(' '))
|
cs |
위와 같은 코드를 실행시키면
I ran the above code
이렇게 나옵니다('d' 와 'e' 사이는 공백이 2칸입니다!)
Here is the result (Between 'd' and 'e' is Two spaces )
따라서 문자열만 필요하다 할때는 split()을 쓰셔도 되겠지만
space 도 필요하다 판단되시면 split(' ')을 쓰셔야 겠습니다.
So If you need only strings , You can use split()
else if you need space too, You should use split(' ')
1
|
print (''.split.__doc__)
|
cs |
split 에 대한 내용을 읽어보면 아래와 같습니다
This is document of split()
반응형
'python-기타' 카테고리의 다른 글
Google Analytics Data API과 Python을 활용한 데이터 수집(Data collection using Google Analytics Data API and Python) (0) | 2023.05.11 |
---|---|
Python isnumeric()에 관한 건 (0) | 2022.10.21 |
print vs pprint (0) | 2021.12.30 |
reverse 와 reversed 차이 (0) | 2021.12.28 |
댓글