python 函数2
2020-12-13 15:24
标签:linux nbsp lin byte bsp sci 字典 turn div nums = [1,2,3,4,5] map函数 map(函数,序列) map 是把数组中的值一个一个的进行某种处理,把处理后的值放到一个新的数组中,并返回这个新的数组。 map(lambda x:x++2,[1,2,3,4]) 返回的是可迭代对象 for i in map(lambda x:x++2,[1,2,3,4]): print(i) 3 def test(x): for i in map(test,[1,2,3,4]): 0 >>> list(map(test,[1,2,3,4])) filter函数 filter是通过某种筛选条件把数组中符合条件的值放到一个新的数组中,并返回这个新数组 filter(函数,序列) 拿出布尔值 >>> list(filter(lambda x:x.startswith("a"),["aa","bb","abc","abd"])) def test1(x): >>> list(filter(test1,["aa","bb","abc","abd"])) reduce函数 reduce处理一个序列,把序列合并操作 >>> def add(x, y): return x+y reduce(add, [1,2,3,4]) 10 abs() 绝对值 all() 拿出值做布尔预算 bool 转化为bool值 bytes("aa‘,encoding="utf-8").decode("utf-8") >>> bytes("选项",encoding="utf-8") bytes(b‘\xe9\x80\x89\xe9\xa1\xb9‘).decode("utf-8") chr() ascii码 dir() 查看 divmod(10,3) (3,1) 取商取余 eval() 函数 简单表达式 print(eval(‘1+2‘)) 3 字符串转字典 print(eval("{‘name‘:‘linux‘,‘age‘:18}") {‘name‘:‘linux‘,‘age‘:18} 全局变量 globals() 局部变量 locals() max() 最大值 min() 最小值 python 函数2 标签:linux nbsp lin byte bsp sci 字典 turn div 原文地址:https://www.cnblogs.com/hywhyme/p/11580915.html
4
5
6
if(x>=1):
x = x - 1
return x+test(x)
else:
return 0
print(i)
1
3
6
[0, 1, 3, 6]
[‘aa‘, ‘abc‘, ‘abd‘]
if(len(x) > 2):
return True
else:
return False
[‘abc‘, ‘abd‘]
b‘\xe9\x80\x89\xe9\xa1\xb9‘
‘选项‘
上一篇:再学IHanlder 类----------------关于Asp.net与iis原理网上看博客收获写一个验证码用一般处理程序记的好长时间前就写过不过现在再看有点不一样的感觉
下一篇:高性能Web开发系列