函数
Roger-Mbiama-Assogo的Python项目详细描述
rédiger«angoso.jpg»$angoso.net s[i]=x第i项替换为x s[i:j]=t从i到j的s片被iterable t的内容替换 del s[i:j]与s[i:j]=[]相同 s[i:j:k]=t将s[i:j:k]的元素替换为t(1)的元素 del s[i:j:k]从列表中删除s[i:j:k]的元素 s.append(x)与s[len(s):len(s)]=[x]相同(2) s.延伸(x)与s[len(s):len(s)]=x(3)相同 s.count(x)返回s[i]==x的i的数目 s.index(x[,i[,j]])返回最小的k,使得s[k]==x和i<;=k<;j(4) s.插入(i,x)与s[i:i]=[x]相同(5) s.pop([i])与x=s[i];del s[i];return x(6) s.删除(x)与删除s[s.索引(x)](4)相同 s.reverse()将s的项反转到位(7) s.排序([cmp[,key[,reverse]])
>>> from string import Template >>> s = Template('$who likes $what') >>> s.substitute(who='angosso', what='ubuntu NIS') 'angosso likes ubuntu NIS' >>> d = dict(who='angosso') >>> Template('Give $who $100').substitute(d) Traceback (most recent call last): [...] ValueError: Invalid placeholder in string: line 1, col 10 >>> Template('$who likes $what').substitute(d) Traceback (most recent call last): [...] KeyError: 'what' >>> Template('$who likes $what').safe_substitute(d) 'angosso likes $what'