'Python'에 해당하는 글 2건

출처 : http://stackoverflow.com/questions/7877850/python-2-7-print-thread-safe


from __future__ import print_function
print = lambda x: sys.stdout.write("%s\n" % x)



WRITTEN BY
RootFriend
개인적으로... 나쁜 기억력에 도움되라고 만들게되었습니다.

,

출처 : 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
개인적으로... 나쁜 기억력에 도움되라고 만들게되었습니다.

,