2013年6月30日

devi into python 笔记(三)callable getattr lambda表达式

摘要: 常用的函数:callable():如果所给参数是可调用的,返回True 不可调用返回Fasle。这里指的是否能调用说的是方法、类方法等有doc string的东西,一个单纯的字符串等就不算了。import string#之前用过的join方法#punctuation给出了可用的标点符号,他实际上就是一个字符串,里面给出了有效可用的标点符号。print string.punctuationprint callable(string.join), callable(string.punctuation)getattr():比较另类也很强大的一个函数,返回的是一个函数的引用l = [1, 2, 3] 阅读全文

posted @ 2013-06-30 21:59 李皮筋 阅读(977) 评论(0) 推荐(0)

devi into python 笔记(二)元组 变量声明 和列表解析

摘要: 元组tuple: 类似list,只是tuple是不可变的list。类似java的String都是不可改变的。注意:tuple没有方法(有待考证),不可以像list那样那个list.pop 或者list.append()等操作。但是可以用 in 来判断一个元素是否在tuple中:mytuple = ('a', 'b', 'c') print 'a' in mytuple, 'd' in mytupletuple与list相比较: tuple更安全,提供了“写保护”,当想要一组只用来遍历的数据时推荐使用tuple。 t 阅读全文

posted @ 2013-06-30 20:49 李皮筋 阅读(457) 评论(0) 推荐(0)

导航