python 内置函数一

#内置函数
a=-3
b=abs(a)
print(b)
#all传参数为列表或元组
c=all(["a","b","1"])
c1=all(["a","b",""])
print(c) #True
print(c1) #False
c=any(("a","b","1"))
c1=any([0,"",""])
print(c) #True
print(c1) #False
ascii(object) #它会自动调用object中的__repr__方法 得到返回值
class A():
def __repr__(self):
return "hello"
a=A();
b=ascii(a)
print(b)#hello
a=bin(3)
print(a)#转化为二进制 0b代表二进制
b=bytearray("哈哈",encoding="utf-8")#转化为字符数组
print(b)
c=bytes("哈哈",encoding="utf-8")
print(c)
#callable判断传入的参数是否可执行
def a():
return 1
b=callable(a)
print(b)#True
l=[]
c=callable(l)
print(c)#False
#chr,ord chr 把数字转化为asc码,ord把asc转为数字
a=chr(99)
print(a)
c=ord('c')
print(c)
compile #主要用于编译,把字符串转为python代码来执行
print(dir([]))#查看列表的方法
c=divmod(3,10)#返回一个元组由商和余数构成
print(c)
a=["a","b","c","d"]
for b,item in enumerate(a,1):
print(b,item)
posted @ 2018-02-02 16:23  罗亮玉  阅读(71)  评论(0编辑  收藏  举报