摘要: Your task is to define the following two methods for the intSet class: Define an intersect method that returns a new intSet containing elements that a 阅读全文
posted @ 2017-12-11 10:19 爱学英语的程序媛 阅读(483) 评论(0) 推荐(0) 编辑
摘要: 首先是单下划线开头,这个被常用于模块中,在一个模块中以单下划线开头的变量和函数被默认当作内部函数,如果使用 from a_module import * 导入时,这部分变量和函数不会被导入。不过值得注意的是,如果使用 import a_module 这样导入模块,仍然可以用 a_module._so 阅读全文
posted @ 2017-12-11 10:04 爱学英语的程序媛 阅读(343) 评论(0) 推荐(0) 编辑
摘要: culinary tradition 烹饪传统 crunchy 松脆的 boutique 精品店 migraine 偏头痛 colon 冒号 towel 毛巾 ecstatic 狂喜的 bok choy 青菜 saute (vi.)炒,炒的 edamame 毛豆 scallion 葱 阅读全文
posted @ 2017-12-11 10:02 爱学英语的程序媛 阅读(207) 评论(0) 推荐(0) 编辑
摘要: 1. repr() 函数将对象转化为供解释器读取的形式。 语法 以下是 repr() 方法的语法: 参数 object -- 对象。 返回值 返回一个对象的 string 格式。 str和repr都是用来将数字,列表等类型转化为字符串的形式,但不同之处在于str更加类似于C语言中使用printf输出 阅读全文
posted @ 2017-12-10 22:09 爱学英语的程序媛 阅读(8957) 评论(0) 推荐(0) 编辑
摘要: 1.Python异常类 Python是面向对象语言,所以程序抛出的异常也是类。常见的Python异常有以下几个,大家只要大致扫一眼,有个映像,等到编程的时候,相信大家肯定会不只一次跟他们照面(除非你不用Python了)。 异常 描述 NameError 尝试访问一个没有申明的变量 ZeroDivis 阅读全文
posted @ 2017-12-08 21:46 爱学英语的程序媛 阅读(2965) 评论(0) 推荐(0) 编辑
摘要: 在函数内部定义变量时,他们与函数外部具有相同名称的其他变量没有任何关系,即变量名称对于函数来说是局部的,这称为变量的作用域,示例如下: def func_local(x): print 'x is', x x = 2 print 'Chanaged local x to',x x = 50 func 阅读全文
posted @ 2017-12-06 20:11 爱学英语的程序媛 阅读(553) 评论(0) 推荐(0) 编辑
摘要: 原代码: def fib(n): if n == 1: return 1 elif n == 2: return 2 else: return fib(n-1)+fib(n-2) 改进后: def fib_efficient(n,d): if n in d: return d[n] else: an 阅读全文
posted @ 2017-12-05 21:40 爱学英语的程序媛 阅读(278) 评论(0) 推荐(0) 编辑
摘要: python provides a general purpose HOP,map simple form-a unary function and a collection of suitable arguments 代码: for e in map(abs,[1,-2,3,-4]): print 阅读全文
posted @ 2017-12-04 20:37 爱学英语的程序媛 阅读(175) 评论(0) 推荐(0) 编辑
摘要: 在讲is和==这两种运算符区别之前,首先要知道Python中对象包含的三个基本要素,分别是:id(身份标识)、python type()(数据类型)和value(值)。is和==都是对对象进行比较判断作用的,但对对象比较判断的内容并不相同。下面来看看具体区别在哪。 Python中比较两个对象是否相等 阅读全文
posted @ 2017-12-04 17:22 爱学英语的程序媛 阅读(163) 评论(0) 推荐(0) 编辑
摘要: avoid mutating a list as you are iterating over it 代码: def remove_dups(L1,L2): for e in L1: if e in L2: L1.remove(e) L1=[1,2,4,5]L2=[2,3,1,6]remove_du 阅读全文
posted @ 2017-12-04 17:17 爱学英语的程序媛 阅读(219) 评论(0) 推荐(0) 编辑