
# print()
# input()
# len()
# type()
# int()
# str()
# list()
# tuple()
# dict()
# set()
# float()
# id()
l = [1,2,3,5,23,235,2]
sum(l) 求和
max(l) 求最大值
min(l) 求最小值
avg = sum(l)/len(l) 求平均值
round(avg,3) 保留3位小数
any([False,False,True]) list里只要有一个为true,就返回true
all([False,False,True]) list里必须都为true,才返回true
chr() 把ASCII码转成对应的值
chr(65)-->A
ord() 把值转成对应的ASCII码
ord(A)-->65
bin() 十进制转二进制
int(“1010”,base=2) 二进制转十进制
int(“12”,base=8) 八进制转成十进制
int(“a”,base=16) 十六进制转十进制
oct() 十进制转八进制
hex() 十进制转十六进制

字符集:
ASCII
gb2312
gbk
unicode 万国码
utf-8
divmod(10,3) 取商和取余数
locals() 取当前函数里面的所有局部变量
globals() 取全局变量
name = "abc"
def test():
age = 19
addr = "beijing"
print(locals())
print(globals())
test()
zip()
usernames = [‘admin‘,‘test‘,‘dev‘]
passwrods = [89,100,61]
passwrods2 = [123,456,789]
for u,p,z in zip(usernames,passwrods,passwrods2):
print(u,p,z)
print(list(zip(usernames,passwrods)))
print(dict(zip(usernames,passwrods)))
sorted() 排序
s=‘876498765‘
print(‘ ‘.join(sorted(s)))
d = {‘admin‘: 89, ‘test‘: 100, ‘dev‘: 61}
def x(l):
return l[1]
print(d.items())
print( sorted(d.items(),key=x,reverse=True) )
print(
sorted(d.items(),key=lambda x:x[1],reverse=True)
)
test = lambda x:x*3
print(test(3))
lambda 只能定义一些简单的功能
map()
l = [1,2,3,4,43,634,63,4634,63,636,23]
l2 = [ str(i) for i in l]
def func(x):
x = str(x)
if len(x)==1:
return ‘00‘+x
elif len(x)==2:
return ‘0‘+x
return x
l2 = list(map(func,l)) l 传给func(x), 循环调用函数,保存结果到一个list里面
l = [1,2,3,4,43,634,63,4634,63,636,23]
l2 = list( map(lambda x:str(x),l) )
l2 = list(map(str,l))
print(l2)
filter()
l = [1,2,3,4,43,634,63,4634,63,636,23]
def func(x):
return x % 2 == 0
print( list(filter(func,l)) )
print( list(map(func,l)) )
#sum min max round zip divmod locals sorted filter map
原文:https://www.cnblogs.com/my-own-goddess/p/14781610.html