python 序列类型可用的内建函数
2016-05-21 10:03
375 查看
python中序列类型可用的内建函数很多,现举例如下图:
1》enumerate( )参数可以是字符串,列表,元组,字典
>>> enumerate('python')
<enumerate object at 0x06AB6508>
>>> e=enumerate('python')
>>> list(e)
[(0, 'p'), (1, 'y'), (2, 't'), (3, 'h'), (4, 'o'), (5, 'n')]
>>> d
{'a': 1, 'c': 3, 'b': 2}
>>> e=enumerate(d)
>>> e
<enumerate object at 0x06A11648>
>>> list(e)
[(0, 'a'), (1, 'c'), (2, 'b')]
2》 len( )参数可以是字典,字符串,列表,元组
>>> d={'a':1,'b':2,'c':3}
>>> d
{'a': 1, 'c': 3, 'b': 2}
>>> len(d)
3
3》max( ) min( )参数可以是字符串,列表,元组,字典
>>> max({"a":22,"b":2})
'b'
>>> min((2,3,4))
2
4》reversed( ) 详见:python 内置函数 reversed()
5》sorted( )详见: python sorted()函数
6》sum( )参数可以是列表,元组
>>> sum([1,2,3])
6
>>> l
[1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> sum(l)#累加的初始值默认是0
45
>>> sum(l,10)#累加的初始值指定为10
55
7》zip( )参数可以是列表,元组,字符串
>>> zip([1,2,3,4],[1,2,3,4],[1,2,3,4])
[(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4)]
>>> zip((1,2,3,4),(1,2,3,4),(1,2,3,4))
[(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4)]
>>> zip('python','python','python')
[('p', 'p', 'p'), ('y', 'y', 'y'), ('t', 't', 't'), ('h', 'h', 'h'), ('o', 'o', 'o'), ('n', 'n', 'n')]
1》enumerate( )参数可以是字符串,列表,元组,字典
>>> enumerate('python')
<enumerate object at 0x06AB6508>
>>> e=enumerate('python')
>>> list(e)
[(0, 'p'), (1, 'y'), (2, 't'), (3, 'h'), (4, 'o'), (5, 'n')]
>>> d
{'a': 1, 'c': 3, 'b': 2}
>>> e=enumerate(d)
>>> e
<enumerate object at 0x06A11648>
>>> list(e)
[(0, 'a'), (1, 'c'), (2, 'b')]
2》 len( )参数可以是字典,字符串,列表,元组
>>> d={'a':1,'b':2,'c':3}
>>> d
{'a': 1, 'c': 3, 'b': 2}
>>> len(d)
3
3》max( ) min( )参数可以是字符串,列表,元组,字典
>>> max({"a":22,"b":2})
'b'
>>> min((2,3,4))
2
4》reversed( ) 详见:python 内置函数 reversed()
5》sorted( )详见: python sorted()函数
6》sum( )参数可以是列表,元组
>>> sum([1,2,3])
6
>>> l
[1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> sum(l)#累加的初始值默认是0
45
>>> sum(l,10)#累加的初始值指定为10
55
7》zip( )参数可以是列表,元组,字符串
>>> zip([1,2,3,4],[1,2,3,4],[1,2,3,4])
[(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4)]
>>> zip((1,2,3,4),(1,2,3,4),(1,2,3,4))
[(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4)]
>>> zip('python','python','python')
[('p', 'p', 'p'), ('y', 'y', 'y'), ('t', 't', 't'), ('h', 'h', 'h'), ('o', 'o', 'o'), ('n', 'n', 'n')]
相关文章推荐
- python 字符串操作 str
- Python基础
- 百度图片爬虫-python语言
- Python处理海量手机号码
- python基础
- python基础
- Python之路,Day2
- 第六节,初识python和字符编码
- python列表的常用操作方法小结
- python实现用户登录系统
- python字符串的常用操作方法小结
- python实现简单购物商城
- Beginner's Guide to Python-新手指导
- python 字典 dict
- Python之路—Day2
- Python 序列化
- python基础
- Cobra —— 可视化Python虚拟机 and 图解python
- 在Ubuntu 12.04中安装python3.2.2
- 深度学习(三)denoise autoencoder的Python实现