共計 224 個字符,預(yù)計需要花費 1 分鐘才能閱讀完成。
在 Python 中,可以使用 strip()
方法來刪除字符串兩端的空白字符(包括空格、制表符、換行符等)。
例如:
s = " hello world "
print(s.strip()) # 輸出結(jié)果為 "hello world"
如果想刪除字符串中間的空白字符,可以使用 replace()
方法將空白字符替換為空字符串。
例如:
s = "hello world"
s = s.replace(" ", "")
print(s) # 輸出結(jié)果為 "helloworld"
丸趣 TV 網(wǎng) – 提供最優(yōu)質(zhì)的資源集合!
正文完