s = " hello world "
print(s.strip())
# Output: "hello world"
s = " hello world "
print(s.replace(" ", ""))
# Output: "helloworld"
s = " hello world "
print("".join(s.split()))
# Output: "helloworld"
import re
s = " hello world "
print(re.sub(r"\s+", "", s))
# Output: "helloworld"
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:php去除空格的方法有哪些