#!/usr/bin/python
# -*- coding utf8 -*-
'''
abs() dict() help() min() setattr()
all() dir() hex() next() slice()
any() divmod() id() object() sorted()
ascii() enumerate() input() oct() staticmethod()
bin() eval() int() open() str()
bool() exec() isinstance() ord() sum()
bytearray() filter() issubclass() pow() super()
bytes() float() iter() print() tuple()
callable() format() len() property() type()
chr() frozenset() list() range() vars()
classmethod() getattr() locals() repr() zip()
compile() globals() map() reversed() __import__()
complex() hasattr() max() round()
delattr() hash() memoryview() set()
'''
#abs() #绝对值
bo = all([1,2,3]) #取出所有的对象判断布尔值 如果所有为True返回True
print(bo)
bo=all('')#空也为True
print(bo)
print(any([0, None, '', 1])) #取出所有对象判断布尔值 一个为真则为真
print(any('')) #空值为False
print(bin(10)) #10转2进制
print(hex(17)) #转16
print(oct(9)) #转8进制
#bool() 0 None 空为False 其余为True
def func():
pass
print(callable(func))#判断是否可调用对象
print(chr(68)) #ascii转换
print(ord('d')) #ascii转换
#后续讲内置函数
# classmethod
# staticmethod
# property
res = complex(1+2j)
print(res.real)
print(res.imag)
#结果位1.0 2.0 复数的实部 虚部
#面向对象反射
# delattr
# hasattr
# getattr()
# setattr()
#工厂函数
# dict
# int
# str
# set
# list
#2
#!/usr/bin/python
# -*- coding utf8 -*-
l=[]
print(dir(l))#查看目录下的属性
#print(help(l))#帮助信息
print(divmod(10,3)) #除法 可以用于分页的计算
#执行结果(3, 1)
cmd = 'print("你愁啥")'
eval(cmd) #执行字符串中命令 取消字符串格式
#eval简单示例 字符串转字典
dic="{'a':1,'b':2}"
d=eval(dic)
with open('a.txt','w',encoding='utf-8') as f:
user_dic={'name':'xp','age':22}
f.write(str(user_dic))
with open('a.txt','r',encoding='utf-8') as f:
dic = f.read()
print(dic, type(dic))
dic = eval(dic)
print(d,type(d))
#map reduce filter 下文
#frozenset() 定义不可变集合
s={1,2}
s.add(3)
print(s)
s=frozenset({1,2})
s='{}{}{}'.format('xp',18,180)
print(s)
print(hash('dddddsdadfaasf')) #hash值
'''
1.只要校验内容一致 , 那hash结果永远一致
2.不可逆
3.只要采用的哈希算法一样,那无论被校验内容长度多少 结果都一致
'''
x=1
y=x
print(id(x),id(y))
print(x is y) #身份运算符
print(x==y) #判断值
#面向对象
#isinstance()
#issubclass()
#len 长度
#list 列表
#max 最大
'''
max
min
sorted
'''
#ord ascii表反推
print(pow(10,2,3)) #前2个平方 和第三个取余
#repr() 相比str更适合机器
#reversed 反转成迭代器
l = ['a',2,3,4]
for i in reversed(l):
print(i)
print(list(reversed(l))) #list sum tuple也都支持迭代器协议
i = reversed(l)
for x in i:
print(x)
print(list(i)) #迭代器迭代完毕 没有值
print(round(3.1415926535897932,5)) #round 保留小数位数,四舍五入
#slice 切片 重复利用
l=[1,2,3,4,5]
print(l[1:4])#第二个到第4个 也可指定步长
s = slice(1,4,2)
print(l[s])
#vars 无参 和 locals()一样
# 有参数 __dict__
#zip 拉链 只找能对应上的
s='hello'
l=[1,2,3,4,5]
z=zip(s,l)
print(z)
for i in z:
print(i)
'''
zip拉链执行结果
('h', 1)
('e', 2)
('l', 3)
('l', 4)
('o', 5)
'''
#__import__
# import time
__import__('time') #以字符串的形式导入模块
#或者
m='time'
__import__(m)
m=__import__('time')
m.sleep(3) #m也支持导入模块的功能
#面向对象里补充
# super
#
# isinstance
# issubclass
#
#
# classmethod
# staticmethod
# property
#
# delattr
# hasattr
# getattr
# setattr
#