python标准库:
os:提供与操作系统相关联的函数
sys:通常用于命令行参数
re:正则匹配
math:数学运算
datetime:处理日期时间
字典删除键:
dic={"name":"zs", "age":14}
del dic["name"]
字典合并键:
dic2={"name":"ls"}
dic.update(dic2)
python实现列表去重:
list1=[11,12,13,14,15,12,13,11,15,15]
=> list1=[11,12,13,14,15]
2. [x for x in list1]
=> list1=[11,12,13,14,15]
python内建数据类型有哪些?
int str bool list tuple dict
两个列表[1,5,7,9]和[6,2,2,8]合并为[1,2,2,5,7,8,9]
list1 = [1,5,7,9]
list2 = [6,2,2,8]
list1.extend(list2) # 合并
print(list1) => [1,5,7,9,6,2,2,8]
list1.sort(reverse = False) # 排序
print(list1) =>[1,2,2,5,7,8,9]
a="张明 98分",用re,sub将98替换成100
import re
a = "张明 98分"
b = re.sub(r"\d+","100",a)
print(b) => 张明 100分
原文:https://www.cnblogs.com/YY-kele/p/14389780.html