溫馨提示×

python怎么去除文本的空格

小億
130
2023-11-13 10:21:35
欄目: 編程語言

在Python中,可以使用字符串的 strip() 方法去除文本的空格。strip() 方法會刪除字符串開頭和結尾的空格。

示例代碼如下:

text = "   hello world   "
new_text = text.strip()
print(new_text)  # 輸出結果為 "hello world"

如果要刪除字符串中所有的空格,可以使用 replace() 方法將空格替換為空字符串。

示例代碼如下:

text = "   hello world   "
new_text = text.replace(" ", "")
print(new_text)  # 輸出結果為 "helloworld"

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女