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