Python字符串处理:去除空格并替换空格为特定字符
以下是使用Python编写的代码实现上述功能:
string = ' a b c ef g '
# 去除开头和结尾中的空格
string = string.strip()
# 替换中间的空格为'o'
string = string.replace(' ', 'o')
print(string)
输出结果为:'a boocoefg'
原文地址: https://www.cveoy.top/t/topic/kMn 著作权归作者所有。请勿转载和采集!