print( all([1,-5,3]) )#如果可迭代对象里所有元素都为真则返回真。0不为真
print( any([1,2]) )#如果数据里面任意一个数据为真返回则为真
a= ascii([1,2,"天气"])#把一个内存数据对象转成字符串表现形式打印出来
print(type(a),[a])
bin #把一个数字转二进制
a = bytes("abcde",encoding="utf-8")#字节数组
b = bytearray("abcde",encoding="utf-8")#可修改的二进制字节格式
print( b[1] )
b[1]= 50
print(b)
print(a.capitalize(),a)#判断是否可以调用,能够加括号的就可以调用
def sayhi():pass
print( callable(sayhi) )
chr(98)#数字对应字母
ord(a)#字母对应数字
#斐波那契数列
code = '''
def fib(max): #10
n, a, b = 0, 0, 1
while n < max: #n<10
#print(b)
yield b
a, b = b, a + b
#a = b a =1, b=2, a=b , a=2,
# b = a +b b = 2+2 = 4
n = n + 1
return '---done---'
#f= fib(10)
g = fib(6)
while True:
try:
x = next(g)
print('g:', x)
except StopIteration as e:
print('Generator return value:', e.value)
break
'''
a={}
print(dir(a))#dir可以查看有哪些方法
print(divmod(5,1))#divmod求商和余数
exec(code)#可实现动态导入功能,远程传递代码
py_obj = compile(code,"err.log","exec")
eval(py_obj)#功能同上
x=1
print(eval('x+1'))#eval把字符串变字典返回2
#匿名函数
(lambda n:print(n))(5) #lambda匿名函数
calc=lambda n:print(n)
calc(7)
calc = lambda n:3 if n<4 else n
print(calc(1))
res = filter(lambda n:n>5,range(10))#filter过滤功能
for i in res:
print(i)
res = map(lambda n:n*2,range(10))#列表生成式[i*2 for i in rang(10)]
for i in res:
print(i)
# res = [ lambda i:i*2 for i in range(10)]#同上
import functools #reduce被引入标准库内
res = functools.reduce( lambda x,y:x+y,range(10 ))#累加
res2 = functools.reduce( lambda x,y:x*y,range(1,10 ))
# print(res )
# print(res2 )
# #
a = frozenset([1,4,333,212,33,33,12,4])#冻结的,不可比变列表
print(globals())#字典,判断一个变量是否存在,整个程序的变量的变量名是k变量对应值是valley
def test():
local_var =333
print(locals())
print(globals())
test()
print(globals())
print(globals().get('local_var'))
max#返回最大值
a = {6:2,8:0,1:4,-5:6,99:11,4:22}
print( sorted(a.items()) )#按照Key进行排序变成列表
print( sorted(a.items(),key=lambda x:x[1]) )#按照vell排序
# print(a )
oct#转八进制
a = [1,2,3,4,5,6]
b = ['a','b','c','d']
for i in zip(a,b):#拉链
print(i)
import decorator
__import__('decorator')
reversed(seq)#反转
round()#保留两位小数
slice()#切片