2018年3月3日

think python 第17章 classes and methods

摘要: 17.1object-oriented features 17.2printing objects 在16章中,定义了一个Time类,后续练习写了一个print_time函数。如果想调用这个函数,必须要给这个函数传递一个Time对象作为参数。如果要把print_time转换成方法,需要把函数定义转移 阅读全文

posted @ 2018-03-03 10:21 土间埋 阅读(193) 评论(0) 推荐(0) 编辑

2017年12月8日

think python 第16章 classes and functions

摘要: 16.1 time 16.2pure functions 编写两个函数,实现时间相加功能。 测试: 16.3modifiers 16.4prototyping versus planning(原型设计与计划) 其实就是将问题普遍化看似将问题复杂化,有时却简化了问题(因为特殊情况变少,出错概率也降低) 阅读全文

posted @ 2017-12-08 11:09 土间埋 阅读(165) 评论(0) 推荐(0) 编辑

2017年12月6日

think python 第15章 classes and objects

摘要: 15.1user-defined types A user-defined type is also called a class. A class definition looks like this: class Point(object): '''Represents a point in 2 阅读全文

posted @ 2017-12-06 20:53 土间埋 阅读(225) 评论(0) 推荐(0) 编辑

2017年12月1日

think python 第12章 tuples

摘要: 12.1tuples are immutable 创建元组的关键是使用‘,’,要创建只含一个元素的元组,需要包含最后的逗号。 创建元组的另一个方法是使用内置函数tuple。没有参数时,创建一个空元组。 如果参数是一个序列(字符串、列表或元组),返回结果是使用序列中的元素构成的元组。 大多数的列表运算 阅读全文

posted @ 2017-12-01 21:37 土间埋 阅读(203) 评论(0) 推荐(0) 编辑

thinkpython 第14章 files

摘要: 恢复内容开始 14.1persistence 14.2reading and wroiting 使用open('','w')写入模式打开已经存在的文件时,会清空原先的数据并重新开始,所以需要小心。如果文件不存在,那么将会创建一个新的文件 14.3format operator write的参数必须是 阅读全文

posted @ 2017-12-01 20:35 土间埋 阅读(168) 评论(0) 推荐(0) 编辑

2017年11月29日

thinkpython第11章dictionaries

摘要: 字典有点类似于列表,但是表现的更为一般。字典的索引(键)几乎可以是任意类型。 11.1dictionary as a set of counters 字典中的get函数,get('key',default value)。如果键在字典里,get返回对应的值;否则返回缺省值。所以我们可以把上述代码变成: 阅读全文

posted @ 2017-11-29 14:43 土间埋 阅读(322) 评论(0) 推荐(0) 编辑

2017年11月27日

think python 第10章 lists

摘要: 10.1列表就是序列 10.2列表是可变的 10.3遍历列表 10.4lists operations +是连接操作;*是给定次数重复列表 10.5lists slices 10.6lists methods append添加至列表尾部,extend添加一个列表至列表尾部;sort从小到大排序 10 阅读全文

posted @ 2017-11-27 22:10 土间埋 阅读(183) 评论(0) 推荐(0) 编辑

think python 第9章 case study:word play

摘要: 9.1reading word lists download words.txt以后,跟编码文件放置在同一文件夹之下。 书中的内容是: 本机(python3.63): 我们也可以使用strip剔除掉换行符 打印文本的每一个单词 9.2exercises 编写一个函数has_no_e,如果给定的单词不 阅读全文

posted @ 2017-11-27 20:17 土间埋 阅读(432) 评论(0) 推荐(0) 编辑

2017年11月24日

think python 第8章字符串

摘要: 8.1字符串是一个序列 8.2len 8.3traveral with a for loop 1.通过while循环遍历字符串 2.通过for循环遍历 8.4string slices 数组[a:b] 左闭右开 8.5 strings are immutable 字符串是不可变的,即不可以修改一个已 阅读全文

posted @ 2017-11-24 12:55 土间埋 阅读(300) 评论(0) 推荐(0) 编辑

2017年11月22日

think python第7章 iteration

摘要: 7.1multiple assignment 多重赋值可以使两个变量相等,却不总是保持相等。如: 7.2updating variables 更新一个变量,首先要进行初始化 7.3 while语句 7.4break语句 7.5平方根 7.6算法 7.7debugging 插入print测试 7.9测 阅读全文

posted @ 2017-11-22 19:13 土间埋 阅读(106) 评论(0) 推荐(0) 编辑

导航