内置函数
print(all([1,2,3,4]))#True 都为真才为真 print(all([1,2,3,0]))#False print(all([1,2,3,False]))#False print(any([1,2,3,4]))#True 都为False才为假 print(any([0,0,0,0]))#False print(max([1,2,5,2])) print(min([1,2,5,2])) print(round(2.3455,2))#2.35 取小数点后固定位数,会四舍五入 a='1' print(dir(a))#可以调用的函数 print(bin(10))#0b1010 10进制转2进制 print(bin(2))# 10进制转2进制 print(chr(98))#b ascii 转字符 print(ord('a'))#97 字符转ascii print(hex(11))#数字换16进制 0xb print(oct(11))#数字换8进制 0o13 s = ''' for i in range(10): print(i) ''' exec(s)#动态执行python代码 # res = eval('1+1')#执行简单代码 res = eval('[1,2,3]')#执行简单代码 print(res) # filter()#过滤 # map() def jishu(num): if num%2==0: return True l=range(1,11) l2=[] for i in l: if jishu(i): l2.append(i) # print(l2) #自动循环,与上面功能相同 result = list(filter(jishu,l))#[2, 4, 6, 8, 10] print(result) result = list(map(jishu,l))#保存函数的返回值 [None, True, None, True, None, True, None, True, None, True] print(result) re = list(map(str,range(1,12)))#['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11'] print(re) def test(): a=1 b=2 print(locals())# 返回局部变量 {'a': 1, 'b': 2} print(globals())#返回全局变量 # test() a = ['zjr','test','tzy'] b = ['123','555','7867ty'] for u,p in zip(a,b): print(u) print(p)