在Python中,可以使用strip()方法去除字符串两端的空格。示例如下:
strip()
s = " hello world " s_stripped = s.strip() print(s_stripped)
输出结果为:
hello world