python字符串操作--strip()方法移除最外侧的前导和末尾字符 发表于 2020-12-26 分类于 Python strip() 方法用于移除字符串最外侧的前导和末尾字符,返回移除后的新字符串 格式及参数1str.strip([chars]) str : 字符串 chars : 移除的字符,省略或为 None 时默认移除空格, chars 参数并非指定单个前缀或后缀,而是会移除参数值的所有组合 参考资料 实例(3.8.8)12345678910str1 = ' abcdefg 'str2 = '***abcdefg****'str3 = 'www.gaoyuanqi.cn'# 默认移除空格print(str1.strip())# 移除 * 如果字符连续则一并移除print(str2.strip('*'))# 在开头端移除字符时若遇到不包含于 chars 中的字符停止print(str3.strip('wcn.'))