Do you want to remove only one space character or multiple spaces?
def strip_one(s):
Ifs.endswith("): s = s[:-1] #Check that the last is ""
If s.startswith("): s = s[1:] #Check that the first is ""
return s
a = " hello "
print strip_one(a)
str.strip([chars])
은 스트링 맨앞/뒤의 chars
를 찾아 제거합니다.
chars
를 지정하지 않은 경우 모든 종류의 공백 문자를 제거하니
" "만 제거하고 싶다면 strip(" ")과 같이 사용하세요.
a = " hello\nworld\n"
print "--strip(' ') start---"
print a.strip(" ")
print "---------end---------"
print "----strip() start----"
print a.strip()
print "---------end---------"
Results are
--strip(' ') start---
hello
world
---------end---------
----strip() start----
hello
world
---------end---------
915 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
618 Uncaught (inpromise) Error on Electron: An object could not be cloned
581 PHP ssh2_scp_send fails to send files as intended
612 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.