python学习笔记六:内置函数
一、数学相关1、绝对值:abs(-1) 2、最大最小值:max([1,2,3])、min([1,3]) 3、序列长度:len('abc')、len([1,3])、len((1,3)) 4、取模:divmod(5,2)//(2,1) 5、乘方:pow(2,3,4)//2**3/4 6、浮点数:round(1)//1.0 二、功能相关1、函数是否可调用:callable(funcname),注意,funcname变量要定义过 2、类型判断:isinstance(x,list/int) 3、比较:cmp('hello','hello') 4、快速生成序列:(x)range([start,] stop[,step]) 三、类型转换1、int(x) 2、long(x) 3、float(x) 4、complex(x) //复数 5、str(x) 6、list(x) 7、tuple(x) //元组 8、hex(x) 9、oct(x) 10、chr(x)//返回x对应的字符,如chr(65)返回‘A’ 11、ord(x)//返回字符对应的ASC码数字编号,如ord('A')返回65 四、字符串处理1、首字母大写:str.capitalize >>>
>>> .replace(,
>>> .split(,,]
可以传二个参数,第二个参数为切割次数 4、字符串转换为大写:str.upper 5、字符串转换为小写:str.lower 6、每个单词第一个字母转换为大写,其余小写:str.title() 7、判断字符串: s.isalnum()
s.isalpha()
s.isdigit()
s.islower()
s.isupper()
s.istitle()
s.isspace()
五、序列处理函数1、len:序列长度 2、max:序列中最大值 3、min:最小值 4、filter:过滤序列 >>> filter( x:x%2==0,[1,4,5,62,6]
>>> name=[,,>>> age=[20,30,40>>> tel=[,,>>>,20,),(,),(,40,)]
>>> name=[,>>>)]
>>> a=[1,5>>> b=[2,6>>>1,2),(3,4),(5,6>>> map( x,y:x*2,12,30]
>>> l=range(1,101>>>1,6,7,8,9,10,11,13,14,15,16,17,18,19,21,22,23,24,25,26,27,28,29,31,32,33,34,35,36,37,38,39,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100>>> reduce( x,y:x+5050
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |