【Python】删除字符串首尾的空字符 空格 回车 换行等

    def del_endswith_none(str1: str):
        """
        删除字符串首尾的空字符(空格、换行)
        :param str1:
        """
        s = str1
        if str1 is not None:
            while True:
                if s.endswith(' ') or s.endswith('    ') or s.endswith('
') or s.endswith('
') or s.endswith('
'):
                    s = s[:-1]
                elif s.startswith(' ') or s.startswith('    ') or s.startswith('
') or s.startswith('
') or s.startswith('
'):
                    s = s[1:]
                else:
                    break
        return s
原文地址:https://www.cnblogs.com/danhuai/p/13914053.html