1、列表/字符串去重 set()
list1 = ['a','b','a','b','c'] l1 = set(list1) # 去重,set()同样适用于字符串 print(l1) new_l1 = list(l1) #转为列表 print(new_l1)
输出:
['b', 'a', 'c']
2、strip()
strip() 方法用于移除字符串头尾指定的字符(默认为空格或换行符)或字符序列。
语法:str.strip([chars]);
# -*- coding: UTF-8 -*- str = "123abcrunoob321" string1 = str.strip( '12' ) # 字符序列为 12 print (string1) # 字符序列为 12



