删除字符串 末尾空格的方法
在Python中,可以使用strip()方法删除字符串末尾的空格。例如:
s = " hello world "
s = s.strip()
print(s) # 输出:hello world
strip()方法还可以指定要删除的字符,例如:
s = " hello world "
s = s.strip(" d")
print(s) # 输出:hello worl
上面的代码中,strip()方法指定要删除的字符为空格和字母d,因此末尾的空格和字母d都被删除了。
原文地址: https://www.cveoy.top/t/topic/b2kR 著作权归作者所有。请勿转载和采集!