....................................................2
1.2.2Python语言发展简介........................................................................................2
1.2.3Python语言的前景............................................................................................2
1.3Python环境安装............................................................................................................3
1.3.1Python3.7.x安装...............................................................................................3
1.3.2PyCharm安装....................................................................................................4
1.4学语言先学注释............................................................................................................8
1.4.1注释符号............................................................................................................9
1.4.2多行注释............................................................................................................9
1.5认识变量......................................................................................................................10
1.5.1变量命名规则..................................................................................................11
1.5.2不合规变量名举例..........................................................................................11
1.6打印输出函数print()...................................................................................................12
1.7数学运算及优先级问题..............................................................................................12
1.8赋值运算符..................................................................................................................13
2无门槛掌握数据类型与输入/输出函数.....................................................14
2.1基本数据类型..............................................................................................................14
2.1.1数值数据类型..................................................................................................15
2.1.2整数的不同形式表示......................................................................................15
2.1.3数据类型强制转换..........................................................................................16
2.1.4扩展几个数值数据类型常用的函数..............................................................17
2.1.5布尔值数据类型..............................................................................................18
2.1.6字符串数据类型..............................................................................................18
2.2输入与输出..................................................................................................................21
2.2.1print()函数格式化输出....................................................................................22
2.2.2format()函数.....................................................................................................23
2.2.3input()函数数据输入.......................................................................................24
3无转折不编程.........................................................................................25
3.1关系运算符..................................................................................................................25
3.2算术运算符..................................................................................................................26
3.3逻辑运算符..................................................................................................................27
3.4编程中的转折——流程控制......................................................................................27
3.4.1if语句..............................................................................................................27
3.4.2if…else…语句.................................................................................................29
3.4.3if…elif…else…语句........................................................................................29
3.4.4if语句的嵌套...................................................................................................30
4列表一学完,Python会一半...................................................................31
4.1列表是个啥..................................................................................................................31
4.1.1列表定义..........................................................................................................31
4.1.2列表读取..........................................................................................................32
4.1.3列表切片..........................................................................................................33
4.1.4列表相关内置函数..........................................................................................33
4.1.5列表元素的修改与删除..................................................................................34
4.1.6列表相加、相乘、删除..................................................................................35
4.2初识Python面向对象.................................................................................................36
4.2.1字符串对象的方法..........................................................................................36
4.2.2快速获取系统内置方法..................................................................................37
4.3通过方法增删列表元素..............................................................................................38
4.3.1追加列表元素..................................................................................................38
4.3.2插入列表元素..................................................................................................39
4.3.3删除列表元素..................................................................................................40
4.4列表排序......................................................................................................................40
4.4.1排序方法sort()................................................................................................41
4.4.2排序函数sorted().............................................................................................41
4.5其他列表方法..............................................................................................................42
4.5.1检索元素索引..................................................................................................42
4.5.2统计列表元素出现次数..................................................................................42
4.5.3转换为字符串..................................................................................................43
4.5.4追加列表..........................................................................................................43
4.6多维列表......................................................................................................................43
4.7特殊的列表字符串......................................................................................................44
4.7.1字符串索引与切片..........................................................................................44
4.7.2可用于字符串的部分函数和方法..................................................................44
4.7.3将字符串转换为列表......................................................................................44
5Python循环的本质就是一段代码懒得重复写..........................................45
5.1for循环........................................................................................................................45
5.1.1for循环基本使用............................................................................................45
5.1.2for循环嵌套if判断语句................................................................................46
5.2range()函数..................................................................................................................46
5.3for循环补充知识........................................................................................................48
5.3.1for循环嵌套....................................................................................................48
5.3.2break终止循环................................................................................................49
5.3.3continue继续循环...........................................................................................49
5.3.4for…else循环..................................................................................................50
5.4while循环....................................................................................................................51
5.4.1while循环的经典应用....................................................................................51
5.4.2while循环其他说明........................................................................................52
6Python元组,不可变的列表...................................................................53
6.1元组的定义..................................................................................................................53
6.2读取元组中的元素......................................................................................................54
6.3元组的其他知识补充..................................................................................................54
6.4元组与列表转换..........................................................................................................55
6.5内置函数zip().............................................................................................................55
6.6元组的功能与应用场景..............................................................................................56
7字典怎么查,Python字典就怎么用........................................................57
7.1字典的基本操作..........................................................................................................57
7.1.1字典的定义......................................................................................................57
7.1.2获取字典的值..................................................................................................58
7.1.3增加元素、修改元素、删除元素..................................................................58
7.1.4字典的补充知识..............................................................................................59
7.2字典的遍历..................................................................................................................60
7.2.1遍历字典的键值..............................................................................................60
7.2.2遍历字典的键..................................................................................................61
7.2.3遍历字典的值..................................................................................................61
7.3字典与其他数据类型的结合......................................................................................62
7.3.1列表嵌套字典..................................................................................................62
7.3.2字典嵌套列表..................................................................................................62
7.4字典的方法..................................................................................................................62
7.4.1fromkeys()方法................................................................................................62
7.4.2get()方法..........................................................................................................63
7.4.3setdefault()方法................................................................................................63
7.4.4pop()方法.........................................................................................................64
8Python中无序且元素唯一的数据类型——集合......................................65
8.1集合是什么..................................................................................................................65
8.1.1集合的声明......................................................................................................65
8.1.2set()函数定义集合...........................................................................................66
8.2集合的操作..................................................................................................................67
8.2.1交集..................................................................................................................67
8.2.2并集..................................................................................................................67
8.2.3差集..................................................................................................................68
8.2.4对称差集..........................................................................................................68
8.3集合的方法..................................................................................................................69
8.3.1集合的增删......................................................................................................69
8.3.2集合的其地方法..............................................................................................70
8.4集合可用的内置函数和冻结集合..............................................................................71
9函数是Python基础部分的第一道难关....................................................72
9.1函数出现的背景..........................................................................................................72
9.2函数初接触..................................................................................................................72
9.2.1函数的定义......................................................................................................72
9.2.2无参数无返回值的函数..................................................................................73
9.3函数的参数设计..........................................................................................................74
9.3.1传递一个参数..................................................................................................74
9.3.2传递多个参数..................................................................................................74
9.3.3关键词参数......................................................................................................75
9.3.4参数默认值......................................................................................................75
9.4函数返回值..................................................................................................................76
9.4.1返回None........................................................................................................76
9.4.2返回一个值......................................................................................................76
9.4.3返回多个值......................................................................................................77
9.4.4返回字典与列表..............................................................................................77
9.5调用函数时参数是列表..............................................................................................77
9.6局部变量与全局变量..................................................................................................78
9.7传递任意数量的参数..................................................................................................79
9.7.1普通参数与任意参数的组合..........................................................................79
9.7.2普通参数与任意数量的关键词参数..............................................................80
9.8函数的扩展学习..........................................................................................................81
10Python面向对象的编程.......................................................................82
10.1类的定义与使用........................................................................................................82
10.1.1定义类、属性与方法....................................................................................82
10.1.2属性与方法的调用........................................................................................83
10.1.3类的构造函数................................................................................................84
10.1.4属性初始值....................................................................................................85
10.2封装............................................................................................................................86
10.2.1私有属性........................................................................................................86
10.2.2私有方法........................................................................................................87
10.3继承............................................................................................................................88
10.3.1继承的简单应用............................................................................................88
10.3.2子类与父类有相同名称的属性或方法........................................................89
10.3.3子类用父类的方法........................................................................................90
10.4多态............................................................................................................................91
10.5多重继承....................................................................................................................92
10.6对象的数据类型判断................................................................................................92
10.7isinstance()函数.........................................................................................................92
10.8特殊属性、方法........................................................................................................93
11Python模块的设计与应用...................................................................95
11.1将函数放到模块中....................................................................................................95
11.2应用函数模块............................................................................................................96
11.2.1import导入模块............................................................................................96
11.2.2导入模块的某个函数....................................................................................97
11.2.3as别名............................................................................................................97
11.3将类放到模块中........................................................................................................98
11.3.1import导入模块............................................................................................98
11.3.2导入模块中的类............................................................................................99
11.4常见模块....................................................................................................................99
11.4.1随机数random模块......................................................................................99
11.4.2时间模块......................................................................................................101
12Python文件读取与写入.....................................................................102
12.1文件夹和文件路径..................................................................................................102
12.1.1绝对路径和相对路径..................................................................................103
12.1.2os模块与os.path模块................................................................................103
12.1.3路径检查方法..............................................................................................105
12.1.4目录操作......................................................................................................105
12.1.5获取文件大小..............................................................................................106
12.1.6获取指定目录下的所有内容......................................................................106
12.2Python读写文件......................................................................................................106
12.2.1读取文件......................................................................................................106
12.2.2写入文件......................................................................................................109
12.3shutil模块................................................................................................................110
12.3.1文件复制......................................................................................................110
12.3.2复制目录......................................................................................................111
12.3.3多功能move()方法.....................................................................................111
12.3.4删除有数据的目录......................................................................................111
13Python程序异常处理与logging模块................................................112
13.1程序异常..................................................................................................................112
13.1.1最常见的错误——除数为0.......................................................................112
13.1.2try…except语句..........................................................................................113
13.1.3try…except…else语句................................................................................114
13.2异常类型..................................................................................................................115
13.2.1常见的异常类型..........................................................................................115
13.2.2捕捉多个异常..............................................................................................116
13.2.3一个except捕获多个异常..........................................................................116
13.2.4直接抛出异常..............................................................................................116
13.3finally语句..............................................................................................................117
13.4日志模块logging.....................................................................................................117
13.4.1日志信息等级..............................................................................................117
13.4.2格式化logging日志信息............................................................................118
13.4.3将程序日志输出到文件中..........................................................................119
13.4.4停用程序日志..............................................................................................120
14在Python中操作SQLite数据库.......................................................121
14.1SQLite基本使用.....................................................................................................121
14.2建立SQLite数据库表............................................................................................122
14.3向表中增加数据......................................................................................................124
14.4查询数据库中的表数据..........................................................................................125
14.5更新表数据..............................................................................................................126
14.6删除表数据..............................................................................................................127
15Python中的多线程与多进程..............................................................128
15.1Python中的多线程..................................................................................................128
15.1.1简单的多线程..............................................................................................129
15.1.2向子线程中传递参数..................................................................................130
15.1.3线程命名......................................................................................................131
15.1.4Daemon守护线程.......................................................................................133
15.1.5堵塞主线程..................................................................................................134
15.1.6使用is_alive()方法检验子线程是否在工作..............................................135
15.1.7自定义线程类..............................................................................................136
15.1.8资源锁定与解锁..........................................................................................136
15.2subprocess模块.......................................................................................................137
15.2.1Popen()方法.................................................................................................138
15.2.2Popen()方法的参数.....................................................................................138
15.2.3通过关键字start打开程序.........................................................................138
第2部分进阶篇
16列表与元组、字典与集合..................................................................139
16.1为何列表和元组总放在一起..................................................................................139
16.1.1列表和元组的切片......................................................................................140
16.1.2负数索引与二者相互转换..........................................................................140
16.1.3列表与元组的存储方式..............................................................................140
16.1.4列表和元组的应用场景..............................................................................141
16.2字典与集合的那些事儿..........................................................................................143
16.2.1字典和集合的基础操作..............................................................................143
16.2.2字典与集合的排序......................................................................................145
16.2.3字典与集合的效率问题..............................................................................146
17列表推导式与字典推导式..................................................................148
17.1列表推导式..............................................................................................................148
17.2字典推导式..............................................................................................................150
17.3元组推导式与集合推导式......................................................................................151
18lambda表达式..................................................................................152
18.1lambda表达式的基本使用.....................................................................................152
18.2lambda表达式与def定义函数的区别..................................................................153
18.3lambda表达式的应用场景.....................................................................................154
18.4不要滥用lambda表达式........................................................................................155
19内置函数filter()、map()、reduce()、zip()、enumerate()..................156
19.1filter()函数...............................................................................................................156
19.2map()函数................................................................................................................156
19.3reduce()函数.............................................................................................................157
19.4zip()函数..................................................................................................................158
19.5enumerate()函数.......................................................................................................159
20函数装饰器........................................................................................160
20.1装饰器的基本使用..................................................................................................160
20.2对带参数的函数进行装饰......................................................................................162
20.3多个装饰器..............................................................................................................164
20.4functools.wraps........................................................................................................168
20.5基于类的装饰器......................................................................................................169
20.6内置装饰器..............................................................................................................170
21闭包...................................................................................................171
21.1闭包的基本操作......................................................................................................171
21.2闭包的作用域..........................................................................................................172
21.3闭包的作用..............................................................................................................173
21.4判断闭包函数..........................................................................................................173
21.5闭包存在的问题......................................................................................................174
22Python中的日期与时间.....................................................................175
22.1日期/时间模块简介.................................................................................................175
22.2time时间模块..........................................................................................................176
22.2.1get_clock_info()函数...................................................................................176
22.2.2获取时间戳..................................................................................................178
22.2.3获取可读时间..............................................................................................178
22.2.4单调时间monotonictime............................................................................179
22.2.5处理器时钟时间..........................................................................................179
22.2.6性能计数器time.perf_counter.....................................................................180
22.2.7时间组件......................................................................................................180
22.2.8解析和格式化时间......................................................................................181
22.2.9time模块......................................................................................................182
22.3datetime模块...........................................................................................................182
22.3.1date类..........................................................................................................182
22.3.2time类..........................................................................................................184
22.3.3datetime类...................................................................................................184
22.3.4timedelta类..................................................................................................184
22.4calendar模块...........................................................................................................185
23global和nonlocal作用域..................................................................186
23.1Python中的作用域..................................................................................................186
23.2global关键字...........................................................................................................187
22.3nonlocal关键字.......................................................................................................189
24Python中的哈希表与可哈希对象......................................................191
24.1哈希表(散列表)..................................................................................................191
24.2可哈希与不可哈希..................................................................................................191
24.3hash()函数................................................................................................................192
24.4hashlib模块.............................................................................................................193
25Python内置模块之random...............................................................194
25.1基本随机函数..........................................................................................................194
25.1.1seed()与random()函数................................................................................194
25.1.2getstate()和setstate(state)函数....................................................................195
25.2扩展随机函数..........................................................................................................196
25.2.1randint()和randrange()函数........................................................................196
25.2.2getrandbits(k)和choice(seq)函数................................................................197
25.2.3shuffle(seq)和sample(pop,k)函数...............................................................197
25.3分布随机函数..........................................................................................................197
25.3.1uniform(a,b)、betavariate和triangular函数..............................................198
25.3.2其他分布随机函数......................................................................................198
26Python内置模块之re,正则表达式的初阶用法................................199
26.1re库的应用..............................................................................................................199
26.1.1正则表达式语法..........................................................................................199
26.1.2re库的基本用法..........................................................................................200
26.2re库相关函数说明......................................................................................201
26.2.1re.search()函数................................................................................201
26.2.2re.match()函数.............................................................................................202
26.2.3re.findall()函数.............................................................................................202
26.2.4re.split()函数................................................................................................202
26.2.5re.finditer()函数...........................................................................................204
26.2.6re.sub()函数...............................................................................204
26.3re库的面向对象写法...........................................................................205
26.4re库的match对象..................................................................................205
26.4.1match对象的属性.......................................................................................205
26.4.2match对象的方法.......................................................................................206
27sys库、os库、getopt库与filecmp库..............................................207
27.1os库........................................................................................................207
27.1.1os库路径操作.............................................................................................208
27.1.2os库进程管理.............................................................................................209
27.1.3os库运行环境相关参数..............................................................................209
27.2sys库.......................................................................................................210
27.2.1常见参数......................................................................................................210
27.2.2常见方法......................................................................................................211
27.3getopt库...........................................................................................212
27.4filecmp库...................................................................................................213
27.4.1filecmp.cmp()、filecmp.cmpfiles()函数......................................................213
27.4.2目录比较......................................................................................................214
28类函数、成员函数、静态函数、抽象函数和方法伪装属性................215
28.1类函数...........................................................................................215
28.2静态函数............................................................................................216
28.3类函数与静态函数在继承类中的表现.........................................217
28.4抽象函数.........................................................................................218
28.5方法伪装属性.....................................................................................219
第3部分实战篇
29爬虫案例——某育儿网问答数据抓取.................................................222
29.1爬虫分析...............................................................................................222
29.1.1类别页面分析..............................................................................................222
29.1.2问题列表页面分析......................................................................................224
29.2爬虫逻辑编码.......................................................................225
29.2.1逻辑编码(伪代码)..................................................................................225
29.2.2requests库中的get()方法说明...................................................................225
29.2.3获取所有的分类页面地址..........................................................................228
29.2.4循环所有的分类页面地址..........................................................................228
29.2.5获取每个分类对应的列表页面,并获取总页码......................................229
29.2.6从第1页循环到总页码..............................................................................229
29.3案例收尾............................................................................................230
30爬虫案例——奥特曼图片采集...........................................................232
30.1目标站点分析..........................................................................................232
30.2编码................................................................................................234
31Python开源框架:Flask...................................................................239
31.1Flask简介.....................................................................................................239
31.1.1完成一个helloworld网页..........................................................................239
31.1.2获取用户请求数据......................................................................................241
31.1.3在URL中提供多个参数............................................................................242
31.2在Flask中操作数据库...............................................................................244
31.3使用Flask模块实现ajax数据入库.....................................................247