Chinaunix首页 | 论坛 | 博客
  • 博客访问: 519217
  • 博文数量: 137
  • 博客积分: 3170
  • 博客等级: 中校
  • 技术积分: 1455
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-17 11:47
文章分类

全部博文(137)

文章存档

2015年(2)

2013年(1)

2012年(6)

2011年(5)

2010年(62)

2009年(61)

我的朋友

分类: Python/Ruby

2010-03-23 16:53:33

1.python里面,下标或索引代表距离第一个元素的偏移。另外,python可以从最后一个元素进行索引,最后一个元素索引为-1。
X[I:J], means “give me
everything in X from offset I up to but not including offset J.”
2. / Classic division
 // floor division  truncate result remainders to their floor regardless of their types.
/ division is slated to be changed to return a true division
result that always retains remainders, even for integers—for example, 1 / 2 will be 0.5,not 0, while 1 // 2 will still be 0.
3. 在Python中, 变量指向对象,而不是指向内存的,variables are
always pointers to objects, not labels of changeable memory areas
4. Python中没有char,只有string
Python strings are categorized as immutable sequences, meaning that the characters they contain have a left-to-right positional order, and that they
cannot be changed in-place.
5.关于python的转义:
>>> 'knight\'s', "knight\"s"
("knight's", 'knight"s')
5.1 raw  string  在字符串之前加入r'',用于过滤\,既关闭转义功能
尤其在打开文件时,需要使用\\转义成一个\,或者使用r代替,使用r更有利于阅读,而外在跨平台情况 下,效果更好 。另外,也可以用于正则表达式。

6.Triple-quoted strings  对于xml和html的多行文本的需求很有用处。
另外,可以很方便的注释一段文字,便于调试。
7.利用gnome-termical和Cpython shell对同样的文件执行,可能
gnome-termical更健壮吧。
8.unicode和ascii混合('ni' + u'spam')为unicode的。
9.unicode和一般string的互相转化用:str和unicode函数。
10. slicing 返回一个新的对象。                             Python returns a new object containing the con-
tiguous section identified by the offset pair。
11. X[1:10:2] 取offset 1,to 9 每隔1个元素。这种操作知道一下。
S[::-1] 实际上是翻转一个字符串。
S[5:1:-1]也可以使用,详见书中。
12. repr()函数和反引号``作用相同,将一个对象转化为字符串。
13.要改变一个string,cteate a new one
14. replace()函数替换操作
S = 'splot' 
S = S.replace('pl', 'pamal')







                                                          

阅读(795) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~