首页 > 编程语言 > 详细

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

时间:2020-11-02 14:30:32      阅读:41      评论:0      收藏:0      [点我收藏+]

 

    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(\r\n) or s.endswith(\r) or s.endswith(\n):
                    s = s[:-1]
                elif s.startswith( ) or s.startswith(    ) or s.startswith(\r\n) or s.startswith(\r) or s.startswith(\n):
                    s = s[1:]
                else:
                    break
        return s

 

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

原文:https://www.cnblogs.com/danhuai/p/13914053.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!