출처 : http://stackoverflow.com/questions/8270092/python-remove-all-whitespace-in-a-string
If you want to remove leading and ending spaces, use str.strip()
:
sentence = ' hello apple'
sentence.strip()
>>> 'hello apple'
If you want to remove all spaces, you can use str.replace()
:
sentence = ' hello apple'
sentence.replace(" ", "")
>>> 'helloapple'
If you want to remove duplicated spaces, use the str.split()
:
sentence = ' hello apple'
" ".join(sentence.split())
>>> 'hello apple'
WRITTEN BY
- RootFriend
개인적으로... 나쁜 기억력에 도움되라고 만들게되었습니다.
,