共計 271 個字符,預計需要花費 1 分鐘才能閱讀完成。
在 Python 中,可以使用字符串的 strip() 方法來去除字符串前后的空格。示例如下:
s = " hello world "
s = s.strip()
print(s) # 輸出:hello world
另外,如果只想去除字符串前面的空格,可以使用 lstrip() 方法;如果只想去除字符串后面的空格,可以使用 rstrip() 方法。示例如下:
s = " hello world "
s = s.lstrip()
print(s) # 輸出:hello world
s = " hello world "
s = s.rstrip()
print(s) # 輸出:hello world
丸趣 TV 網 – 提供最優質的資源集合!
正文完