Python序列——序列操作
来源:互联网 发布:慧源电子商务平台源码 编辑:程序博客网 时间:2024/05/08 13:02
Python中的序列包括,字符串、列表、元组。本文介绍序列的通用操作。
1. 切片中的None
>>> s = 'abcdefg'>>> for i in range(-1, -len(s), -1):... print s[:i]... abcdefabcdeabcdabcaba>>> for i in [None] + range(-1, -len(s), -1):... print s[:i]... abcdefgabcdefabcdeabcdabcaba>>> s[::-1]'gfedcba'>>>
2. 类型转换
- list(iter)
- str(obj)
- unicode(obj)
- basestring()
- tuple(iter)
3. 序列内建函数
- enumerate(iter)
- len(seq)
- max(iter, key=None)
- max(arg0, arg1,…,key=None)
- min(iter, key=None)
- min(arg0, arg1,…,key=None)
- reversed(seq)
- sorted(iter, func=None, key=None, reverse=False)
- sum(seq, init=0)
- zip([it0, it1,…,itN])
>>> for i in enumerate(s):... print i... (0, 'a')(1, 'b')(2, 'c')(3, 'd')(4, 'e')(5, 'f')(6, 'g')>>> len(s)7>>> max(s)'g'>>> min(s)'a'>>> for i in reversed(s):... print i... gfedcba>>> sorted(s, reverse=True)['g', 'f', 'e', 'd', 'c', 'b', 'a']>>> l = range(7)>>> l[0, 1, 2, 3, 4, 5, 6]>>> sum(l)21>>> zip(s,l)[('a', 0), ('b', 1), ('c', 2), ('d', 3), ('e', 4), ('f', 5), ('g', 6)]>>>
1 0
- Python序列——序列操作
- Python——序列
- Python——序列
- python序列化操作
- python序列映射操作
- Python通用序列操作
- python:序列操作
- python--序列操作
- python 序列操作
- Python序列通用操作
- Python序列之通用序列操作
- 20.python——序列的常用操作
- python学习笔记5—序列与列表的操作
- Python序列——字符串
- Python序列——Unicode
- Python序列——列表
- Python序列——字符串
- Python序列——列表
- CSS基础:div设置透明度、圆角、投影
- spring笔记:第一节
- [leetcode[ 【字符串】 44. Wildcard Matching
- eclipse中某工程的断点进不去问题,折腾了N个小时才找到原因,郁闷
- leetcode_c++:Majority Element(169)
- Python序列——序列操作
- lightoj1138Trailing Zeroes (III)
- SQL SERVER 2012、2014网络配置
- Bootstrap学习(一)
- <Fragment>的学习
- LED显示屏
- 【转】Qt中的QString,QByteArray,Qchar, char*
- QtQuick学习笔记之QML布局定位器Row/Column/Grid/Flow
- JVM内存区域划分Eden Space、Survivor Space、Tenured Gen,Perm Gen解释