# 去掉空白的字符 def not_empty(s): return s and s.strip() l=list(filter(not_empty, ['A', '', 'B', None, 'C', ' '])) print(l) ''' ['A', 'B', 'C'] '''