公有方法
序列集合支持索引和分片操作。 索引格式为:seq[i]。负数索引从序列的尾部开始计数,最尾端的元素索引为-1。 分片格式为:seq[start:end],中间用冒号分隔,不包含end。索引可正可负,要求start <= end。
Tuple_namr = (元素1,元素2,...)
Tuple_name = tuple() #创建一个空元组
Tuple_name = tuple(iterable) #用可迭代序列创建一个空元组
创建元组的过程称之为“打包”,将元组中元素分别赋值给多个变量成为“解包”。
使用内建函数len()和range()对元组进行遍历
List_name = [元素1,元素2,...]
List_name = list() #创建空列表
List_name = list(iterable) #利用可迭代集合创建列表
L.append(object) -- append object to end
extend(…)追加对象作为list的单个元素,object可以为任意对象,包括列表/元组等
L.extend(iterable) -- extend list by appending elements from the iterable
+/+=追加可迭代集合到列表,如元组/列表/字典
注意:Extend方法与“+”操作完全等价,都是对可迭代集合进行深拷贝,即执行操作后再改变可迭代集合元素并不影响当前列表。特别地,当可迭代集合为字典时,只对键key进行追加。
L=L1+(iterable)
insert(…)追加可迭代集合到列表,如元组/列表/字典
L.insert(index, object) -- insert object before index
pop(…)插入单个元素
L.pop([index]) -> item -- remove and return item at index (default last)
count(…)弹出指定位置元素
L.count(value) -> integer -- return number of occurrences of value
remove(…)统计指定值出现的次数
L.remove(value) -- remove first occurrence of value
删除首次出现的指定元素
L.index(value, [start, [stop]]) -> integer -- return first index of value
sort(…)返回指定值元素首次出现的索引
L.sort(cmp=None, key=None, reverse=False) -- stable sort *IN PLACE*;
cmp(x, y) -> -1, 0, 1
reverse(…)
L.reverse() -- reverse *IN PLACE*
Dict_name = { key1:value1 , key2:value2 , ... }
Dict_name = dict()
D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.
pop(…)通过key得到value
D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
popitem(…)由于字典是无序的,所以字典的pop()方法必须指定key
D.popitem() -> (k, v), remove and return some (key, value) pair as a 2-tuple
has_key(…)
D.has_key(k) -> True if D has a key k, else False
keys(…)
D.keys() -> list of D's keys
values(…)
D.values() -> list of D's values
items(…)
D.items() -> list of D's (key, value) pairs, as 2-tuples
iterkeys(…)
D.iterkeys() -> an iterator over the keys of D
itervalues(…)
D.itervalues() -> an iterator over the values of D
iteritems(…)
D.iteritems() -> an iterator over the (key, value) items of D
clear(…)
D.clear() -> None. Remove all items from D.
————********—————————-
Str_name = str(" .. ")
Str_name = " .. "
格式1:"%s"%mystr
格式2:"%s%s"%(mystr1,mystr2)
常用格式化字符串的替代符
S.count(sub[, start[, end]]) -> int
startswith(…)返回在[start, end]范围内的子串sub非重叠出现的次数。
S.startswith(prefix[, start[, end]]) -> bool
endswith(…)
S.endswith(suffix[, start[, end]]) -> bool
find(…)判断字符串S的S[start,end]字串是否以suffix结尾
S.find(sub [,start [,end]]) -> int
index(…)查找字串首次出现的索引,查找失败返回-1
S.index(sub [,start [,end]]) -> int
rfind(…)查找字串首次出现的索引,查找失败抛出ValueError异常
S.rfind(sub [,start [,end]]) -> int
rindex(…)查找字串出现的最高索引
S.rindex(sub [,start [,end]]) -> int
isalnum(…)查找字串出现的最高索引
S.isalnum() -> bool
isalpha(…)如果字符串中的所有字符都是数字或者字母,并且至少有一个字符,则返回true,否则返回false
S.isalpha() -> bool
isdigit(…)字符串至少有一个字符并且都是字母,则返回true,否则返回false
S.isdigit() -> bool
islower(…)如果在字符串中的所有字符都是数字并且至少一个字符,则返回 true。否则返回false
S.islower() -> bool
isupper(…)
S.isupper() -> bool
join(…)
S.join(iterable) -> string
lower(…)返回一个字符串,为iterable可迭代对象中字符串的连接。元素之间的分隔符是提供该方法的字符串
S.lower() -> string
upper(…)Return a copy of the string S converted to lowercase.
S.upper() -> string
Return a copy of the string S converted to uppercase.
lstrip(…)
S.lstrip([chars]) -> string or unicode
strip(…)返回删除前导字符的字符串的副本。Chars参数是一个字符串,指定要移除的字符集。如果省略或没有 chars参数默认为删除空格
S.strip([chars]) -> string or unicode
partition(…)返回字符串的一个副本,删除前导和尾随字符。
S.partition(sep) -> (head, sep, tail)
replace(…)在分隔符首次出现位置拆分字符串,并返回包含分隔符之前部分、分隔符本身和分隔符之后部分的3元组。如果找不到分隔符,返回包含字符串本身,跟着两个空字符串的 3 元组。
S.replace(old, new[, count]) -> string
split(…)返回字符串的一个拷贝,其中所有的子串old通过new替换。如果指定了可选参数count,则只有前面的count个出现被替换。
S.split([sep [,maxsplit]]) -> list of strings
rsplit(…)返回字符串中的单词列表,使用sep作为分隔符字符串。如果给出maxsplit,则至多拆分maxsplit次如果没有指定maxsplit或为-1,那么分割的数量没有限制
S.rsplit([sep [,maxsplit]]) -> list of strings
splitlines(…)
S.splitlines(keepends=False) -> list of strings
swapcase(…)返回字符串中行组成的列表,在行的边界截断。换行符不包含在结果列表中,除非给定keepends给定且为真。
S.swapcase() -> string
返回字符串的一个拷贝,其中大写字符转换为小写,小写字符转换为大写。