《用Python玩转数据》学习笔记第2周(Part2)

1、Python字符串格式化:http://www.cnblogs.com/JerySpace/archive/2010/12/17/1909621.html

2、enumerate()用法:在同时需要用到index和value值的时候可以用到enumerate,参数为可遍历的变量,如字符串,列表等,返回enumerate类。 http://www.pythonclub.org/python-basic/built-in

3、read(), readline(), readlines(), xreadlines()
http://blog.csdn.net/longshenlmj/article/details/12570271
xreadlines的原理和xrange差不多。但现在也不推荐使用xreadlines,详见:http://www.oschina.net/question/252490_132790

4、sort(),sorted()
一个排序函数都这么博大精深。学无止境啊!
https://wiki.python.org/moin/HowTo/Sorting
一个简单些的讲解:http://www.jb51.net/article/52730.htm
需要注意:sort(a_list) 修改a_list,但是sorted(a_list) 并不修改a_list,而是生成一个副本

>>> x = [3,2,5,0,1]
>>> x.sort()
>>> print x
[0, 1, 2, 3, 5]
>>> x = [3,2,5,0,1]
>>> print sorted(x)
[0, 1, 2, 3, 5]
>>> print x
[3, 2, 5, 0, 1]

5、如果一个function里的argument前面有*,它的作用是生成tuple,长度不限:

>>> def func(argu1, *argu2):
...     print argu1
...     print argu2
... 
>>> func('A','B','C','D')
A
('B', 'C', 'D')

6、Python2.x和3.x中,urllib的区别:

a new urllib package was created. It consists of code from
urllib, urllib2, urlparse, and robotparser. The old
modules have all been removed. The new package has five submodules:
urllib.parse, urllib.request, urllib.response,
urllib.error, and urllib.robotparser. The
urllib.request.urlopen() function uses the url opener from
urllib2. (Note that the unittests have not been renamed for the
beta, but they will be renamed in the future.)

7、所有标准序列操作,例如分片索引等,对字符串都是适用的,但是字符串都是不可变的,要注意不能对分片数据进行赋值。

8、chr(), unichr(), ord()
http://www.xuebuyuan.com/2067536.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值