最近在看python标准库这本书,第一感觉非常厚,第二感觉,里面有很多原来不知道的东西,现在记下来跟大家分享一下. string类是python中最常用的文本处理工具,在python的标准库中,有大量的工具,可以帮助我们完成高级文本处理. capwords()是将一个字符串中的所有单词的首字母大写. import string s = 'The quick brown fox jumped over the lazy dog.' print s print string.capw
一.列表排序 # python中对列表排序有sort.sorted两种方法,其中sort是列表内置方法,其帮助文档如下:In [1]: help(sorted) Help on built-in function sorted in module builtins: sorted(iterable, /, *, key=None, reverse=False) Return a new list containing all items from the iterable in ascendi
Python学习02 列表 List Python列表 List Python中的列表(List)用逗号分隔,方括号包围(comma-separated values (items) between square brackets). 一个Python列表例子: movies = ['Hello', 'World','Welcome'] 在Python中创建列表时,解释器会在内存中创建一个类似于数组的数据结构来存放数据,数据项自下而上堆放(形成一个堆栈). 列表数据的访问 一般访问索引 可以像访
JUNE 28TH, 2014Tweet This article describes how Python string interning works in CPython 2.7.7. A few days ago, I had to explain to a colleague what the built-in function intern does. I gave him the following example: >>> s1 = 'foo!' >>>
http://www.laurentluce.com/posts/python-string-objects-implementation/ Python string objects implementation June 19, 2011 This article describes how string objects are managed by Python internally and how string search is done. PyStringObject structu
1.列表生成式(List Comprehensions) python中,列表生成式是用来创建列表的,相较于用循环实现更为简洁.举个例子,生成[1*1, 2*2, ... , 10*10],循环用三行: L = [] for i in range(1,11): L.append(i*i) 列表生成式只用一行,前面是生成规则,后面是初始元素,最后还可以加上判断条件: [i*i for i in range(1, 11)] 列表生成式还可以实现多层循环,以及判断,刚刚的栗子再写复杂一点就成了: [a