-------------------------------------------------------------------------------------------------------------------------------------

python3基础

Python3 运算符

目录

算术运算符
比较运算符
赋值运算符
位运算符
逻辑运算符
成员运算符
身份运算符
运算符优先级

算术运算符

数值运算
+ 加法
- 减法
* 乘法
/ 除法,得到一个浮点数
// 取除整数,能除尽的次数
% 取余,除尽后余下的数
** 乘方

回去

比较运算符

== 是否相等
!= 不等于
> 大于
< 小于
>= 大于等于
<= 小于等于

回去

赋值运算符

= 简单的赋值运算符
+= 加法赋值运算符 c += a 等效于 c = c + a
-= 减法赋值运算符 c -= a 等效于 c = c - a
*= 乘法赋值运算符 c *= a 等效于 c = c * a
/= 除法赋值运算符 c /= a 等效于 c = c / a
%= 取模赋值运算符 c %= a 等效于 c = c % a
**= 幂赋值运算符 c **= a 等效于 c = c ** a
//= 取整除赋值运算符 c //= a 等效于 c = c // a
:= 海象运算符 就是将赋值操作集成到条件判断语句中

回去

位运算符

& 真真为真
| 真假为真
^ 按位异或运算符
~ 按位取反运算符
<< 左移动运算符
>> 右移动运算符

回去

逻辑运算符


回去

成员运算符

in 如果在指定的序列中找到值返回 True,否则返回 False。
not in 如果在指定的序列中没有找到值返回 True,否则返回 False。

回去

身份运算符

and 真真为真
or 真假为真
not 取反

回去

运算符优先级

is is 是判断两个标识符是不是引用自一个对象
is not is not 是判断两个标识符是不是引用自不同对象

回去

Python3 数字(Number)

目录

[Python 数字类型转换](#Python 数字类型转换)
[Python 数字运算](#Python 数字运算)
数学函数
随机数函数
三角函数
数学常量

Python 数字类型转换


回去

Python 数字运算


回去

数学函数

abs(x)
ceil(x)
cmp(x, y)
exp(x)
fabs(x)
floor(x)
log(x)
log10(x)
max(x1, x2,...)
min(x1, x2,...)
modf(x)
pow(x, y)
round(x [,n])
sqrt(x)

回去

随机数函数

choice(seq)
randrange ([start,] stop [,step])
random()
seed([x])
shuffle(lst)
uniform(x, y)

回去

三角函数

acos(x)
asin(x)
atan(x)
atan2(y, x)
cos(x)
hypot(x, y)
sin(x)
tan(x)
degrees(x)
radians(x)

回去

数学常量

pi
e

回去

Python3 字符串

目录

[Python 访问字符串中的值](#Python 访问字符串中的值)
[Python 字符串更新](#Python 字符串更新)
Python转义字符
Python字符串运算符
Python字符串格式化
Python三引号
f-string
[Python 的字符串内建函数](#Python 的字符串内建函数)

Python 访问字符串中的值


回去

Python 字符串更新


回去

Python转义字符


回去

Python字符串运算符


回去

Python字符串格式化


回去

Python三引号


回去

f-string


回去

Python 的字符串内建函数

capitalize()
center(width, fillchar)
count(str, beg= 0,end=len(string))
bytes.decode(encoding="utf-8", errors="strict")
encode(encoding='UTF-8',errors='strict')
endswith(suffix, beg=0, end=len(string))	
expandtabs(tabsize=8)
find(str, beg=0, end=len(string))
index(str, beg=0, end=len(string))	
isalnum()
isalpha()
isdigit()
islower()
isnumeric()
isspace()
istitle()
isupper()
join(seq)
len(string)
ljust(width[, fillchar])
lower()
lstrip()
maketrans()
max(str)
min(str)
replace(old, new [, max])
rfind(str, beg=0,end=len(string))
rindex( str, beg=0, end=len(string))
rjust(width,[, fillchar])
rstrip()
split(str="", num=string.count(str))
splitlines([keepends])
startswith(substr, beg=0,end=len(string))
strip([chars])
swapcase()
title()
translate(table, deletechars="")
upper()
zfill (width)
isdecimal()

回去

Python3 列表

目录

访问列表中的值
更新列表
删除列表元素
Python列表脚本操作符
Python列表截取与拼接
嵌套列表
Python列表函数&方法

访问列表中的值


回去

更新列表


回去

删除列表元素


回去

Python列表脚本操作符


回去

Python列表截取与拼接


回去

嵌套列表


回去

Python列表函数&方法

#Python包含以下函数:
len(list)
max(list)
min(list)
list(seq)
#Python包含以下方法:
list.append(obj)
list.count(obj)
list.extend(seq)
list.index(obj)
list.insert(index, obj)
list.pop([index=-1])
list.remove(obj)
list.reverse()
list.sort( key=None, reverse=False)
list.clear()
list.copy()

回去

Python3 元组

目录

访问元组
修改元组
删除元组
元组运算符
元组索引,截取
元组内置函数
关于元组是不可变的

访问元组


[回去](#Python3 元组)

修改元组


[回去](#Python3 元组)

删除元组


[回去](#Python3 元组)

元组运算符


[回去](#Python3 元组)

元组索引,截取


[回去](#Python3 元组)

元组内置函数

len(tuple)
max(tuple)
min(tuple)
tuple(seq)

[回去](#Python3 元组)

关于元组是不可变的


[回去](#Python3 元组)

Python3 字典

目录

访问字典里的值
修改字典
删除字典元素
字典键的特性
字典内置函数&方法

访问字典里的值


回去

修改字典


回去

删除字典元素


回去

字典键的特性


回去

字典内置函数&方法

# Python字典包含了以下内置函数:
len(dict)
str(dict)
type(variable)
# Python字典包含了以下内置方法:
radiansdict.clear()
radiansdict.copy()
radiansdict.fromkeys()
radiansdict.get(key, default=None)
key in dict
radiansdict.items()
radiansdict.keys()
radiansdict.setdefault(key, default=None)
radiansdict.update(dict2)
radiansdict.values()
pop(key[,default])
popitem()

回去

Python3 集合

目录

1、添加元素
2、移除元素
3、计算集合元素个数
4、清空集合
5、判断元素是否在集合中存在
集合内置方法完整列表

1、添加元素


[回去](#Python3 集合)

2、移除元素


[回去](#Python3 集合)

3、计算集合元素个数


[回去](#Python3 集合)

4、清空集合


[回去](#Python3 集合)

5、判断元素是否在集合中存在


[回去](#Python3 集合)

集合内置方法完整列表

add()
clear()
copy()
difference()
difference_update()
discard()
intersection()
intersection_update()
isdisjoint()
issubset()
issuperset()
pop()
remove()
symmetric_difference()
symmetric_difference_update()
union()
update()

[回去](#Python3 集合)

Python3 条件控制

目录

[if 语句](#if 语句)
以下为if中常用的操作运算符:
[if 嵌套](#if 嵌套)

if 语句


[回去](#Python3 条件控制)

以下为if中常用的操作运算符:


[回去](#Python3 条件控制)

if 嵌套


[回去](#Python3 条件控制)

Python3 循环语句

目录

[while 循环](#while 循环)
无限循环
[while 循环使用 else 语句](#while 循环使用 else 语句)
简单语句组
[for 语句](#for 语句)
range()函数
[break 和 continue 语句及循环中的 else 子句](#break 和 continue 语句及循环中的 else 子句)
[pass 语句](#pass 语句)

Python3 迭代器与生成器

目录

迭代器
创建一个迭代器
StopIteration
生成器

迭代器


[回去](#Python3 迭代器与生成器)

创建一个迭代器


[回去](#Python3 迭代器与生成器)

StopIteration


[回去](#Python3 迭代器与生成器)

生成器


[回去](#Python3 迭代器与生成器)

Python3 函数

目录

定义一个函数的方法,语法
函数调用参数传递,必需参数
函数调用参数传递,关键字参数
函数调用参数传递,默认参数
函数调用参数传递,不定长参数
匿名函数方式,语法
return语句作用
强制位置参数

定义一个函数的方法,语法

# def表示函数
def 函数名(参数列表):
    函数体

[回去](#Python3 函数)

函数调用参数传递,必需参数

# 构建函数时,如果有参数,在调用时必须给定参数否者报错
# 示例
def 

[回去](#Python3 函数)

函数调用参数传递,关键字参数

# 关键字参数不需要使用指定位置
# 示例
def runoob(name,age):
    print(name)
    print(age)

runoob(age=50,name='小明')  # 函数调用
# 结果
小明
50

[回去](#Python3 函数)

函数调用参数传递,默认参数

# 示例
def runoob(name,age=40):
    print(name)
    print(age)

runoob(name='小明') # 函数调用
runoob(age=50,name='小王') # 函数调用
# 结果
小明
40
小王
50

[回去](#Python3 函数)

函数调用参数传递,不定长参数

# 示例
def runoob(name,*tu):
    print(name)
    print(tu)

runoob('nihao',2,3,4,'hhh') # 函数调用
# 结果
nihao
(2, 3, 4, 'hhh')

[回去](#Python3 函数)

匿名函数方式,语法


[回去](#Python3 函数)

return语句作用

# 为表达式用于退出函数,选择性向调用方返回一个表达式

[回去](#Python3 函数)

强制位置参数

def f(a, b, /, c, d, *, e, f):
    print(a, b, c, d, e, f)
# a,b必须使用指定位置参数,c,d可以使用指定位置参数或关键字参数,e,f必须使用关键字参数

[回去](#Python3 函数)

Python3 数据结构

目录

将列表当做堆栈使用
将列表当作队列使用
列表推导式
嵌套列表解析
[del 语句](#del 语句)
元组和序列
集合
字典
遍历技巧

将列表当做堆栈使用


[回去](#Python3 数据结构)

将列表当作队列使用


[回去](#Python3 数据结构)

列表推导式


[回去](#Python3 数据结构)

嵌套列表解析


[回去](#Python3 数据结构)

del 语句


[回去](#Python3 数据结构)

元组和序列


[回去](#Python3 数据结构)

集合


[回去](#Python3 数据结构)

字典


[回去](#Python3 数据结构)

遍历技巧


[回去](#Python3 数据结构)

Python3 模块

目录

[import 语句](#import 语句)
[from … import 语句](#from … import 语句)
[from … import * 语句](#from … import * 语句)
深入模块
__name__属性
[dir() 函数](#dir() 函数)
标准模块

从一个包中导入*

import 语句


[回去](#Python3 模块)

from … import 语句


[回去](#Python3 模块)

from … import * 语句


[回去](#Python3 模块)

深入模块


[回去](#Python3 模块)

__name__属性


[回去](#Python3 模块)

dir() 函数


[回去](#Python3 模块)

标准模块


[回去](#Python3 模块)


[回去](#Python3 模块)

从一个包中导入*


[回去](#Python3 模块)

Python3 输入和输出

目录

输出格式美化
旧式字符串格式化
读取键盘输入
读和写文件
不同模式打开文件的完全列表:
文件对象的方法
f.read()
f.readline()
f.readlines()
f.write()
f.tell()
f.seek()
f.close()
[pickle 模块](#pickle 模块)

输出格式美化


[回去](#Python3 输入和输出)

旧式字符串格式化


[回去](#Python3 输入和输出)

读取键盘输入


[回去](#Python3 输入和输出)

读和写文件


[回去](#Python3 输入和输出)

不同模式打开文件的完全列表:

r
rb
r+
rb+
w
wb
w+
wb+
a
ab
a+
ab+

[回去](#Python3 输入和输出)

文件对象的方法


[回去](#Python3 输入和输出)

f.read()


[回去](#Python3 输入和输出)

f.readline()


[回去](#Python3 输入和输出)

f.readlines()


[回去](#Python3 输入和输出)

f.write()


[回去](#Python3 输入和输出)

f.tell()


[回去](#Python3 输入和输出)

f.seek()


[回去](#Python3 输入和输出)

f.close()


[回去](#Python3 输入和输出)

pickle 模块


[回去](#Python3 输入和输出)

Python3 File(文件)方法

目录

[open() 方法](#open() 方法)
语法格式
参数说明
[mode 参数有:](#mode 参数有:)
[file 对象](#file 对象)

open() 方法


[回去](#Python3 File(文件)方法)

语法格式


[回去](#Python3 File(文件)方法)

参数说明

file
mode
buffering
encoding
errors
newline
closefd
opener

[回去](#Python3 File(文件)方法)

mode 参数有:

t
x
b	
+
r
rb
r+
rb+
w
wb
w+
wb+
a
ab
a+
ab+

[回去](#Python3 File(文件)方法)

file 对象

file.close()
file.flush()
file.fileno()
file.isatty()
file.next()
file.read([size])
file.readline([size])
file.readlines([sizeint])
file.seek(offset[, whence])
file.tell()
file.truncate([size])	
file.write(str)
file.writelines(sequence)

[回去](#Python3 File(文件)方法)

Python3 OS 文件/目录方法

目录

[os.access(path, mode)](#os.access(path, mode))
os.chdir(path)
[os.chflags(path, flags)](#os.chflags(path, flags))
[os.chmod(path, mode)](#os.chmod(path, mode))
[os.chown(path, uid, gid)](#os.chown(path, uid, gid))
os.chroot(path)
os.close(fd)
[os.closerange(fd_low, fd_high)](#os.closerange(fd_low, fd_high))
os.dup(fd)
[os.dup2(fd, fd2)](#os.dup2(fd, fd2))
os.fchdir(fd)
[os.fchmod(fd, mode)](#os.fchmod(fd, mode))
[os.fchown(fd, uid, gid)](#os.fchown(fd, uid, gid))
os.fdatasync(fd)
[os.fdopen(fd[, mode[, bufsize]])](#os.fdopen(fd[, mode[, bufsize]]))
[os.fpathconf(fd, name)](#os.fpathconf(fd, name))
os.fstat(fd)
os.fstatvfs(fd)
os.fsync(fd)
[os.ftruncate(fd, length)](#os.ftruncate(fd, length))
os.getcwd()
os.getcwdu()
os.isatty(fd)
[os.lchflags(path, flags)](#os.lchflags(path, flags))
[os.lchmod(path, mode)](#os.lchmod(path, mode))
[os.lchown(path, uid, gid)](#os.lchown(path, uid, gid))
[os.link(src, dst)](#os.link(src, dst))
os.listdir(path)
[os.lseek(fd, pos, how)](#os.lseek(fd, pos, how))
os.lstat(path)
os.major(device)
[os.makedev(major, minor)](#os.makedev(major, minor))
[os.makedirs(path[, mode])](#os.makedirs(path[, mode]))
os.minor(device)
[os.mkdir(path[, mode])](#os.mkdir(path[, mode]))
[os.mkfifo(path[, mode])](#os.mkfifo(path[, mode]))
[os.mknod(filename[, mode=0600, device])](#os.mknod(filename[, mode=0600, device]))
[os.open(file, flags[, mode])](#os.open(file, flags[, mode]))
os.openpty()
[os.pathconf(path, name)](#os.pathconf(path, name))
os.pipe()
[os.popen(command[, mode[, bufsize]])](#os.popen(command[, mode[, bufsize]]))
[os.read(fd, n)](#os.read(fd, n))
[os.read(fd, n)](#os.read(fd, n))
os.readlink(path)
os.remove(path)
os.removedirs(path)
[os.rename(src, dst)](#os.rename(src, dst))
[os.renames(old, new)](#os.renames(old, new))
os.rmdir(path)
os.statvfs(path)
[os.symlink(src, dst)](#os.symlink(src, dst))
os.tcgetpgrp(fd)
[os.tcsetpgrp(fd, pg)](#os.tcsetpgrp(fd, pg))
os.ttyname(fd)
os.unlink(path)
[os.utime(path, times)](#os.utime(path, times))
[os.path 模块](#os.path 模块)
[os.walk(top[, topdown=True[, onerror=None[, followlinks=False]]])](#os.walk(top[, topdown=True[, onerror=None[, followlinks=False]]]))
[os.write(fd, str)](#os.write(fd, str))
os.stat(path)
os.stat_float_times([newvalue])

os.access(path, mode)

```
[回去](#Python3 File(文件)方法)

<h3 id="os.chdir(path)">os.chdir(path)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.chflags(path, flags)">os.chflags(path, flags)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.chmod(path, mode)">os.chmod(path, mode)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.chown(path, uid, gid)">os.chown(path, uid, gid)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.chroot(path)">os.chroot(path)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.close(fd)">os.close(fd)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.closerange(fd_low, fd_high)">os.closerange(fd_low, fd_high)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.dup(fd)">os.dup(fd)</h3>
[回去](#Python3 File(文件)方法)

<h3 id="os.dup2(fd, fd2)">os.dup2(fd, fd2)</h3>
[回去](#Python3 File(文件)方法)


<h3 id="os.fchdir(fd)">os.fchdir(fd)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.fchmod(fd, mode)">os.fchmod(fd, mode)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.fchown(fd, uid, gid)">os.fchown(fd, uid, gid)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.fdatasync(fd)">os.fdatasync(fd)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.fdopen(fd[, mode[, bufsize]])">os.fdopen(fd[, mode[, bufsize]])</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.fpathconf(fd, name)">os.fpathconf(fd, name)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.fstat(fd)">os.fstat(fd)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.fstatvfs(fd)">os.fstatvfs(fd)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.fsync(fd)">os.fsync(fd)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.ftruncate(fd, length)">os.ftruncate(fd, length)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.getcwd()">os.getcwd()</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.getcwdu()">os.getcwdu()</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.isatty(fd)">os.isatty(fd)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.lchflags(path, flags)">os.lchflags(path, flags)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.lchmod(path, mode)">os.lchmod(path, mode)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.lchown(path, uid, gid)">os.lchown(path, uid, gid)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.link(src, dst)">os.link(src, dst)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.listdir(path)">os.listdir(path)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.lseek(fd, pos, how)">os.lseek(fd, pos, how)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.lstat(path)">os.lstat(path)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.major(device)">os.major(device)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.makedirs(path[, mode])">os.makedirs(path[, mode])</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.minor(device)">os.minor(device)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.mkdir(path[, mode])">os.mkdir(path[, mode])</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.mkfifo(path[, mode])">os.mkfifo(path[, mode])</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.mknod(filename[, mode=0600, device])">os.mknod(filename[, mode=0600, device])</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.open(file, flags[, mode])">os.open(file, flags[, mode])</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.openpty()">os.openpty()</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.pathconf(path, name)">os.pathconf(path, name)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.pipe()">os.pipe()</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.popen(command[, mode[, bufsize]])">os.popen(command[, mode[, bufsize]])</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.read(fd, n)">os.read(fd, n)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.read(fd, n)">os.read(fd, n)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.readlink(path)">os.readlink(path)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.remove(path)">os.remove(path)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.statvfs(path)">os.statvfs(path)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.removedirs(path)">os.removedirs(path)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.rename(src, dst)">os.rename(src, dst)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.renames(old, new)">os.renames(old, new)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.rmdir(path)">os.rmdir(path)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.symlink(src, dst)">os.symlink(src, dst)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.tcgetpgrp(fd)">os.tcgetpgrp(fd)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.tcsetpgrp(fd, pg)">os.tcsetpgrp(fd, pg)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.ttyname(fd)">os.ttyname(fd)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.unlink(path)">os.unlink(path)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.utime(path, times)">os.utime(path, times)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.path 模块">os.path 模块</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.walk(top[, topdown=True[, onerror=None[, followlinks=False]]])">os.walk(top[, topdown=True[, onerror=None[, followlinks=False]]])</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.write(fd, str)">os.write(fd, str)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.stat(path)">os.stat(path)</h3>

[回去](#Python3 File(文件)方法)

<h3 id="os.stat_float_times([newvalue])">os.stat_float_times([newvalue])</h3>

[回去](#Python3 File(文件)方法)


## Python3 错误和异常

<h3 id="Python3 错误和异常">目录</h3>

[语法错误](#语法错误)
[异常](#异常)
[异常处理](#异常处理)
[try/except](#try/except)
[try/except...else](#try/except...else)
[try-finally 语句](#try-finally 语句)
[抛出异常](#抛出异常)
[用户自定义异常](#用户自定义异常)
[定义清理行为](#定义清理行为)
[预定义的清理行为](#预定义的清理行为)

<h3 id="语法错误">语法错误</h3>

[回去](#Python3 错误和异常)

<h3 id="异常">异常</h3>

[回去](#Python3 错误和异常)

<h3 id="异常处理">异常处理</h3>

[回去](#Python3 错误和异常)

<h3 id="try/except">try/except</h3>

[回去](#Python3 错误和异常)

<h3 id="try/except...else">try/except...else</h3>

[回去](#Python3 错误和异常)

<h3 id="try-finally 语句">try-finally 语句</h3>

[回去](#Python3 错误和异常)

<h3 id="抛出异常">抛出异常</h3>

[回去](#Python3 错误和异常)

<h3 id="用户自定义异常">用户自定义异常</h3>

[回去](#Python3 错误和异常)

<h3 id="定义清理行为">定义清理行为</h3>

[回去](#Python3 错误和异常)

<h3 id="预定义的清理行为">预定义的清理行为</h3>

[回去](#Python3 错误和异常)


## Python3 面向对象

<h3 id="Python3 面向对象">目录</h3>

[定义类方法,语法](#定义类方法,语法)
[类属性引用和实例化](#类属性引用和实例化)
[类单继承,多继承](#类单继承,多继承)
[方法重写](#方法重写)
[类属性与方法](#类属性与方法)
[类的私有属性](#类的私有属性)
[类的方法](#类的方法)
[类的私有方法](#类的私有方法)
[类的专有方法:](#类的专有方法:)
[运算符重载](#运算符重载)

<h3 id="定义类方法,语法">定义类方法,语法</h3>

class 类名:
def 函数名1(self):
print("hello world")
def 函数名2(self):
print("hello world")
def 函数名n(self):
print("hello world")

[回去](#Python3 面向对象)

<h3 id="类属性引用和实例化">类属性引用和实例化</h3>

class leiming:
name = " " # 公有属性,外部可直接调用
age = 0 # 公有属性,外部可直接调用
__shiyou = 0 # 私有属性,外部不可直接调用
def hanshuming(self,a,b,c):
self.name = a
self.age = b
self.__shiyou =c
print("%d岁的%s 说:我%d岁了" % (self.__shiyou,self.name,self.age))

d = leiming() # 类示例化
d.hanshuming('runoob',10,30) # 调用

[回去](#Python3 面向对象)

<h3 id="类单继承,多继承">类单继承,多继承</h3>

class yinianji: # 基类(父类)
name = ' '
age = 0
def xiaoming(self):
print("nihao")

class xuexiao(yinianji): # 另一个基类(单继承)
def mingdan(self):
print("我们有一年级(yinianji)")

class jiazhang(xuexiao): # 定义子类,多继承,xuexiao继承过yinianji,不用重复继承否者报错
def xiaomingmama(self):
print("我们家小明")

c = jiazhang() 类示例化
c.xiaoming() # 调用父类方法(函数)
c.mingdan() # 调用父类方法(函数)
c.xiaomingmama() # 调用自己方法(函数)

[回去](#Python3 面向对象)

<h3 id="方法重写">方法重写</h3>

class fulei:
def hanshuming(self):
print("这是父类方法")

class zilei(fulei):
def hanshuming(self):
print("这是子类的方法")

a = zilei() # 子类示例化
a.hanshuming() # 调用
super(zilei,a).hanshuming() # super()超类,调用父类已被覆盖的方法

[回去](#Python3 面向对象)

<h3 id="类属性与方法">类属性与方法</h3>

[回去](#Python3 面向对象)

<h3 id="类的私有属性">类的私有属性</h3>


[回去](#Python3 面向对象)

<h3 id="类的方法">类的方法</h3>

[回去](#Python3 面向对象)

<h3 id="类的私有方法">类的私有方法</h3>

[回去](#Python3 面向对象)

<h3 id="类的专有方法:">类的专有方法:</h3>

init
del
repr
setitem
getitem
len
cmp
call
add
sub
mul
truediv
mod
pow

[回去](#Python3 面向对象)

<h3 id="运算符重载">运算符重载</h3>

[回去](#Python3 面向对象)

## Python3 命名空间和作用域

<h3 id="Python3 命名空间和作用域">目录</h3>

[一般有三种命名空间](#一般有三种命名空间)
[作用域](#作用域)
[全局变量和局部变量](#全局变量和局部变量)
[global 和 nonlocal关键字](#模板)

<h3 id="一般有三种命名空间">一般有三种命名空间</h3>

内置名称
全局名称
局部名称

[回去](#Python3 命名空间和作用域)

<h3 id="作用域">作用域</h3>

[回去](#Python3 命名空间和作用域)

<h3 id="全局变量和局部变量">全局变量和局部变量</h3>

[回去](#Python3 命名空间和作用域)

<h3 id="global 和 nonlocal关键字">global 和 nonlocal关键字</h3>
[回去](#Python3 命名空间和作用域)

## Python3 标准库概览

<h3 id="Python3 标准库概览">目录</h3>

[操作系统接口](#操作系统接口)
[文件通配符](#文件通配符)
[命令行参数](#命令行参数)
[错误输出重定向和程序终止](#错误输出重定向和程序终止)
[字符串正则匹配](#字符串正则匹配)
[数学](#数学)
[访问 互联网](#访问 互联网)
[日期和时间](#日期和时间)
[数据压缩](#数据压缩)
[性能度量](#性能度量)
[测试模块](#测试模块)

<h3 id="操作系统接口">操作系统接口</h3>

[回去](#Python3 标准库概览)

<h3 id="文件通配符">文件通配符</h3>

[回去](#Python3 标准库概览)

<h3 id="命令行参数">命令行参数</h3>

[回去](#Python3 标准库概览)

<h3 id="错误输出重定向和程序终止">错误输出重定向和程序终止</h3>

[回去](#Python3 标准库概览)

<h3 id="字符串正则匹配">字符串正则匹配</h3>

[回去](#Python3 标准库概览)

<h3 id="数学">数学</h3>

[回去](#Python3 标准库概览)

<h3 id="访问 互联网">访问 互联网</h3>

[回去](#Python3 标准库概览)

<h3 id="日期和时间">日期和时间</h3>

[回去](#Python3 标准库概览)

<h3 id="数据压缩">数据压缩</h3>

[回去](#Python3 标准库概览)

<h3 id="性能度量">性能度量</h3>

[回去](#Python3 标准库概览)

<h3 id="测试模块">测试模块</h3>

[回去](#Python3 标准库概览)

## Python3 正则表达式

<h3 id="Python3 正则表达式">目录</h3>

[基础](#基础)
[re.match函数](#re.match函数)
[re.search方法](#re.search方法)
[re.match与re.search的区别](#re.match与re.search的区别)
[repl 参数是一个函数](#repl 参数是一个函数)
[findall](#findall)
[re.finditer](#re.finditer)
[re.split](#re.split)
[正则表达式对象](#正则表达式对象)
[正则表达式修饰符 - 可选标志](#模正则表达式修饰符 - 可选标志板)
[正则表达式模式](#正则表达式模式)
[正则表达式实例](#正则表达式实例)

<h3 id="基础">基础</h3>

元字符:
. 匹配除换行符外任意一个字符
[abc] 字符集合,只能表示一个字符位置。匹配所包含的任意一个字符
[^abc] 字符集合,只能表示一个字符位置。匹配除去集合内字符的任意一个字符
[a-z] 字符范围,也是个集合,表示一个字符位置,匹配所包含的任意一个字符
[^a-z] 字符范围,也是个集合,表示一个字符位置,匹配除去集合内字符的任意一个字符
\b 匹配单词的边界,这个字符必须在词首
\B 不匹配单词的边界 ,这个字符可以在词中非首的任意位置
\d [0-9]匹配1位数字,匹配0-9中任意一个数值
\D [0-9)匹配1位非数字,匹配0-9以外任意一个字符
\s 匹配1位空白字符,包括换行符、制表符、空格,[\f\r\n\i\t\v]
\S 匹配1位非空白字符
\w 匹配[a-zA-ZO-9_],包括中文的字,匹配小写,大写包括数字所包含的一个字符位置
\W 匹配\w之外的字符,匹配非小写,大写包括数字所包含的一个字符位置

转义方法:
\n 凡是在正则表达式中有特殊意义的符号,如果想使用它的本意,请使用\转义。反斜杠自身,得使用\\r、 \n还是转义后代表回车、换行

重复使用:

  • 表示前面的正则表达式会重复0次或多次
  • 表示前面的正则表达式重复至少1次,必须出现1次
    ? 表示前面的正则表达式会重复0次或1次
    {n} 重复固定的n次
    {n,} 重复至少n次
    {n.m} 重复n到m次

练习:
1、匹配手机号码
字符串为“手机号码13851888188。”
2、匹配中国座机
字符串为"号码025-83105736,0543-5467328。”
1, 1d(11)
2. 1d(3,4-\d(7,8)

或者二选一:
x|y

捕获(分组):
(pattern)
\数字
(?:pattern)
(?exp) 分组捕获,但是可以通过name访问分组Python语法必须是(Penamexexp)
(?'name'exp)
python的语法:
(?Pexp)

零宽断言(断言=预判,条件必须为真):
(?=exp)
(?<=exp)

负向零宽断言:
(?!exp)
(?<!exp)

注释:
(?#comment)

贪婪与非贪婪:
*?
+?
??
{n,}?
{n,m}?

单行模式和多行模式:
练习:

1、匹配一个0~999之间的任意数字
2、ip地址
3、选出含有ftp的链接,且文件类型是gz或者xz的文件名



[回去](#Python3 正则表达式)

<h3 id="re.match函数">re.match函数</h3>

函数语法:

函数参数说明:

pattern
string
flags

[回去](#Python3 正则表达式)

<h3 id="re.search方法">re.search方法</h3>

函数语法:

函数参数说明:

pattern
string
flags

[回去](#Python3 正则表达式)

<h3 id="re.match与re.search的区别">re.match与re.search的区别</h3>

检索和替换

语法:

参数:

pattern
repl
string
count
flags

[回去](#Python3 正则表达式)

<h3 id="repl 参数是一个函数">repl 参数是一个函数</h3>

compile 函数

语法格式为:

参数:

pattern
flags
re.I

[回去](#Python3 正则表达式)


<h3 id="findall">findall</h3>

语法格式为:

参数:

string
pos
endpos

[回去](#Python3 正则表达式)


<h3 id="re.finditer">re.finditer</h3>

语法格式:

参数:

pattern
string
flags

[回去](#Python3 正则表达式)

<h3 id="re.split">re.split</h3>

语法格式:

参数:

pattern
string
maxsplit
flags

[回去](#Python3 正则表达式)

<h3 id="正则表达式对象">正则表达式对象</h3>

re.RegexObject

re.MatchObject

[回去](#Python3 正则表达式)

<h3 id="正则表达式修饰符 - 可选标志">正则表达式修饰符 - 可选标志</h3>

re.I
re.L
re.M
re.S
re.U
re.X

[回去](#Python3 正则表达式)


<h3 id="正则表达式模式">正则表达式模式</h3>

^
$
.
[...]
[^...]
re*
re+
re?
re{ n}
re{ n,}
re{ n, m}
a| b
(re)
(?imx)
(?-imx)
(?: re)
(?imx: re)
(?-imx: re)
(?#...)
(?= re)
(?! re)
(?> re)
\w
\W
\s
\S
\d
\D
\A
\Z
\z
\G
\b
\B
\n, \t, 等。
\1...\9
\10

[回去](#Python3 正则表达式)

<h3 id="正则表达式实例">正则表达式实例</h3>

python
[Pp]ython
rub[ye]
[aeiou]
[0-9]
[a-z]
[A-Z]
[a-zA-Z0-9]
[^aeiou]
[^0-9]
特殊字符类
.
\d
\D
\s
\S
\w
\W

[回去](#Python3 正则表达式)

## Python CGI编程

<h3 id="Python CGI编程">目录</h3>

[CGI程序实现](#CGI程序实现)
[HTTP头部](#HTTP头部)
[浏览器客户端向服务器传递信息:GET方法和POST方法](#浏览器客户端向服务器传递信息:GET方法和POST方法)
[通过CGI程序传递checkbox数据,Radio数据,Textarea 数据,下拉数据](#通过CGI程序传递checkbox数据,Radio数据,Textarea 数据,下拉数据)
[CGI中使用Cookie](#CGI中使用Cookie)
[cookie的语法](#cookie的语法)
[Cookie设置](#Cookie设置)
[检索Cookie信息](#检索Cookie信息)
[文件上传实例](#文件上传实例)
[文件下载对话框](#文件下载对话框)

<h3 id="CGI程序实现">CGI程序实现</h3>

打开web服务CGI接口,在httpd程序的主配置文件

AddHandler cgi-script .cgi .py # 添加.py后缀,默认访问目录位于/var/www/cgi.bin下.py结尾的python程序

systemctl stop firewalld

systemctl restart httpd

vi /var/www/cgi.bin/hello.py

!/usr/bin/python3

print ("Content-type:text/html")
print () # 空行,告诉服务器结束头部
print ('')
print ('')
print ('')
print ('Hello Word - 我的第一个 CGI 程序!')
print ('')
print ('')
print ('

Hello Word! 我是来自菜鸟教程的第一CGI程序

')
print ('')
print ('')

chmod +x /var/www/cgi.bin/hello.py

[回去](#Python CGI编程)

<h3 id="HTTP头部">HTTP头部</h3>

Content-type:
Expires: Date
Location: URL
Last-modified: Date
Content-length: N
Set-Cookie: String

[回去](#Python CGI编程)

<h3 id="浏览器客户端向服务器传递信息:GET方法和POST方法">浏览器客户端向服务器传递信息:GET方法和POST方法</h3>

URL使用GET方法向.py程序发送参数,?号分割,&符号连接

/cgi-bin/test.py?name=python基础&url=http://www.cnblogs.com/hao-ran/p/12202812.html

HTML表单向.py程序发送参数

action="/cgi-bin/hello_get.py 指定.py程序路径

method="get" 发送方法为get,改为post方法这里修改,别的于get一致

type="text" 类型为text

name="name" 名字为name

type="submit"

python基础教程
站点名称:

站点 URL:

.py程序,通过变量导入html文本

!/usr/bin/python3

CGI处理模块

import cgi, cgitb

创建 FieldStorage 的实例化

form = cgi.FieldStorage()

获取数据

site_name = form.getvalue('name')
site_url = form.getvalue('url')

print ("Content-type:text/html")
print ()
print ("")
print ("")
print ("<meta charset="utf-8">")
print ("菜鸟教程 CGI 测试实例")
print ("")
print ("")
print ("

%s官网:%s

" % (site_name, site_url))
print ("")
print ("")

[回去](#Python CGI编程)

<h3 id="通过CGI程序传递checkbox数据,Radio数据,Textarea 数据,下拉数据">通过CGI程序传递checkbox数据,Radio数据,Textarea 数据,下拉数据</h3>

type="checkbox" checkbox用于提交一个或者多个选项数据

target="_blank" target 属性规定在何处打开链接文档,_blank 在新窗口中打开被链接文档。

python基础教程
站点名称:

站点 URL:





checkbox 方法: 用于提交一个或者多个选项数据

百度搜索

Google翻译





radio 方法:只向服务器传递一个数据

百度搜索

Google翻译





Textarea 方法: 向服务器传递多行数据




HTML 下拉框



文件上传,表单需要设置 enctype 属性为 multipart/form-data 菜鸟教程(runoob.com)

选中文件:

.py程序

!/usr/bin/python3

import cgi,os

a = cgi.FieldStorage()

html_name = a.getvalue('name')
html_url = a.getvalue('url')

if a.getvalue('google'):
html_google="是"
if html_google =="是":
html_name = "谷歌翻译"
html_url = "https://translate.google.cn/"
else:
html_google="否"

if a.getvalue('baidu'):
html_baidu="是"
if html_baidu == "是":
html_name = "百度搜索"
html_url = "https://www.baidu.com/"
else:
html_baidu="否"

if a.getvalue('site'):
site = a.getvalue('site')
if site == "google":
html_name = "谷歌翻译"
html_url = "https://translate.google.cn/"
elif site == "baidu":
html_name = "百度搜索"
html_url = "https://www.baidu.com/"
else:
site = "提交数据为空"

if a.getvalue('textcontent'):
html_text = a.getvalue('textcontent')
else:
html_text = "没有内容"

if a.getvalue('dropdown'):
if a.getvalue('dropdown') == "google":
html_name = "谷歌翻译"
html_url = "https://translate.google.cn/"
elif a.getvalue('dropdown') == "baidu":
html_name = "百度搜索"
html_url = "https://www.baidu.com/"
else:
html_name = "没有内容"

文件上传

检测文件是否上传

print ("Content-type:text/html")
print () # 空行,告诉服务器结束头部
print ('')
print ('')
print ('')
print ('cgi测试')
print ('')
print ('')
print ('

%s 官网是:%s

' % (html_name,html_url))
print ('

你选择了google:%s

' %(html_google))
print ('

你选择了baidu:%s

'%(html_baidu))
print ("

选中的网站是 %s

" % (site))
print ("

输入的内容是: %s

" % (html_text))
print ('')
print ('')

[回去](#Python CGI编程)

<h3 id="CGI中使用Cookie">CGI中使用Cookie</h3>

[回去](#Python CGI编程)

<h3 id="cookie的语法">cookie的语法</h3>

name=name:
expires=date:
path=path:
domain=domain:
secure:

[回去](#Python CGI编程)

<h3 id="Cookie设置">Cookie设置</h3>

[回去](#Python CGI编程)

<h3 id="检索Cookie信息">检索Cookie信息</h3>

[回去](#Python CGI编程)

<h3 id="文件上传实例">文件上传实例</h3>

[回去](#Python CGI编程)

<h3 id="文件下载对话框">文件下载对话框</h3>

[回去](#Python CGI编程)

## Python MySQL - mysql-connector 驱动

<h3 id="Python MySQL - mysql-connector 驱动">目录</h3>

[创建数据库连接](#创建数据库连接)
[创建数据库](#创建数据库)
[创建数据表](#创建数据表)
[主键设置](#主键设置)
[插入数据](#插入数据)
[批量插入](#批量插入)
[查询数据](#查询数据)
[where 条件语句](#where 条件语句)
[排序](#排序)
[Limit](#Limit)
[删除记录](#删除记录)
[更新表数据](#更新表数据)
[删除表](#删除表)

<h3 id="创建数据库连接">创建数据库连接</h3>

[回去](#Python MySQL - mysql-connector 驱动)

<h3 id="创建数据库">创建数据库</h3>

[回去](#Python MySQL - mysql-connector 驱动)

<h3 id="创建数据表">创建数据表</h3>

[回去](#Python MySQL - mysql-connector 驱动)

<h3 id="主键设置">主键设置</h3>

[回去](#Python MySQL - mysql-connector 驱动)

<h3 id="插入数据">插入数据</h3>

[回去](#Python MySQL - mysql-connector 驱动)

<h3 id="批量插入">批量插入</h3>

[回去](#Python MySQL - mysql-connector 驱动)

<h3 id="查询数据">查询数据</h3>

[回去](#Python MySQL - mysql-connector 驱动)

<h3 id="where 条件语句">where 条件语句</h3>

[回去](#Python MySQL - mysql-connector 驱动)

<h3 id="排序">排序</h3>

[回去](#Python MySQL - mysql-connector 驱动)

<h3 id="Limit">Limit</h3>

[回去](#Python MySQL - mysql-connector 驱动)

<h3 id="删除记录">删除记录</h3>

[回去](#Python MySQL - mysql-connector 驱动)

<h3 id="更新表数据">更新表数据</h3>

[回去](#Python MySQL - mysql-connector 驱动)

<h3 id="删除表">删除表</h3>

[回去](#Python MySQL - mysql-connector 驱动)

## Python3 MySQL 数据库连接 - PyMySQL 驱动

<h3 id="Python3 MySQL 数据库连接 - PyMySQL 驱动">目录</h3>

[什么是 PyMySQL?](#什么是 PyMySQL?)
[PyMySQL 安装](#PyMySQL 安装)
[数据库连接](#数据库连接)
[创建数据库表](#创建数据库表)
[数据库插入操作](#数据库插入操作)
[数据库查询操作](#数据库查询操作)
[数据库更新操作](#数据库更新操作)
[删除操作](#删除操作)
[执行事务](#执行事务)
[错误处理](#错误处理)

<h3 id="什么是 PyMySQL?">什么是 PyMySQL?</h3>

[回去](#Python3 MySQL 数据库连接 - PyMySQL 驱动)

<h3 id="PyMySQL 安装">PyMySQL 安装</h3>

[回去](#Python3 MySQL 数据库连接 - PyMySQL 驱动)

<h3 id="数据库连接">数据库连接</h3>

[回去](#Python3 MySQL 数据库连接 - PyMySQL 驱动)

<h3 id="创建数据库表">创建数据库表</h3>

[回去](#Python3 MySQL 数据库连接 - PyMySQL 驱动)

<h3 id="数据库插入操作">数据库插入操作</h3>

[回去](#Python3 MySQL 数据库连接 - PyMySQL 驱动)

<h3 id="数据库查询操作">数据库查询操作</h3>

[回去](#Python3 MySQL 数据库连接 - PyMySQL 驱动)

<h3 id="数据库更新操作">数据库更新操作</h3>

[回去](#Python3 MySQL 数据库连接 - PyMySQL 驱动)

<h3 id="删除操作">删除操作</h3>

[回去](#Python3 MySQL 数据库连接 - PyMySQL 驱动)

<h3 id="执行事务">执行事务</h3>

原子性
一致性
隔离性
持久性

[回去](#Python3 MySQL 数据库连接 - PyMySQL 驱动)

<h3 id="错误处理">错误处理</h3>

Warning
Error
InterfaceError
DatabaseError
DataError
OperationalError
IntegrityError
InternalError
ProgrammingError
NotSupportedError

[回去](#Python3 MySQL 数据库连接 - PyMySQL 驱动)


## Python3 网络编程

<h3 id="Python3 网络编程">目录</h3>

[什么是 Socket?](#什么是 Socket?)
[socket()函数](#socket()函数)
[语法格式](#语法格式)
[参数](#参数)
[Socket 对象(内建)方法](#Socket 对象(内建)方法)
[简单实例](#简单实例)
[服务端](#服务端)
[客户端](#客户端)
[Python Internet 模块](#Python Internet 模块)

<h3 id="什么是 Socket?">什么是 Socket?</h3>

[回去](#Python3 网络编程)

<h3 id="socket()函数">socket()函数</h3>

[回去](#Python3 网络编程)

<h3 id="语法格式">语法格式</h3>

[回去](#Python3 网络编程)

<h3 id="参数">参数</h3>

family
type
protocol

[回去](#Python3 网络编程)

<h3 id="Socket 对象(内建)方法">Socket 对象(内建)方法</h3>

s.bind()
s.listen()
s.accept()
s.connect()
s.connect_ex()
s.recv()
s.send()
s.sendall()
s.recvfrom()
s.sendto()
s.close()
s.getpeername()
s.getsockname()
s.setsockopt(level,optname,value)
s.getsockopt(level,optname[.buflen])
s.settimeout(timeout)
s.gettimeout()
s.fileno()
s.setblocking(flag)
s.makefile()

[回去](#Python3 网络编程)

<h3 id="简单实例">简单实例</h3>

[回去](#Python3 网络编程)

<h3 id="服务端">服务端</h3>

[回去](#Python3 网络编程)

<h3 id="客户端">客户端</h3>

[回去](#Python3 网络编程)

<h3 id="Python Internet 模块">Python Internet 模块</h3>

HTTP
NNTP
FTP
SMTP
POP3
IMAP4
Telnet
Gopher

[回去](#Python3 网络编程)



## Python3 SMTP发送邮件

<h3 id="Python3 SMTP发送邮件">目录</h3>

[Python创建 SMTP 对象语法](#Python创建 SMTP 对象语法)
[参数说明:](#参数说明:)
[Python SMTP对象使用sendmail方法发送邮件,语法](#Python SMTP对象使用sendmail方法发送邮件,语法)
[实例](#实例)
[使用Python发送HTML格式的邮件](#使用Python发送HTML格式的邮件)
[Python 发送带附件的邮件](#Python 发送带附件的邮件)
[在 HTML 文本中添加图片](#在 HTML 文本中添加图片)
[使用第三方 SMTP 服务发送](#使用第三方 SMTP 服务发送)

<h3 id="Python创建 SMTP 对象语法">Python创建 SMTP 对象语法</h3>

[回去](#Python3 SMTP发送邮件)

<h3 id="参数说明:">参数说明:</h3>

host
port
local_hostname

[回去](#Python3 SMTP发送邮件)

<h3 id="Python SMTP对象使用sendmail方法发送邮件,语法">Python SMTP对象使用sendmail方法发送邮件,语法</h3>

参数说明:

from_addr
to_addrs
msg

[回去](#Python3 SMTP发送邮件)

<h3 id="实例">实例</h3>

[回去](#Python3 SMTP发送邮件)

<h3 id="使用Python发送HTML格式的邮件">使用Python发送HTML格式的邮件</h3>

[回去](#Python3 SMTP发送邮件)

<h3 id="Python 发送带附件的邮件">Python 发送带附件的邮件</h3>

[回去](#Python3 SMTP发送邮件)

<h3 id="在 HTML 文本中添加图片">在 HTML 文本中添加图片</h3>

[回去](#Python3 SMTP发送邮件)

<h3 id="使用第三方 SMTP 服务发送">使用第三方 SMTP 服务发送</h3>

[回去](#Python3 SMTP发送邮件)

## Python3 多线程

<h3 id="Python3 多线程">目录</h3>

[线程可以分为:](#线程可以分为:)
[Python3 线程中常用的两个模块为:](#Python3 线程中常用的两个模块为:)
[开始学习Python线程](#开始学习Python线程)
[函数式:调用 _thread 模块中的start_new_thread()函数来产生新线程。语法](#函数式:调用 _thread 模块中的start_new_thread()函数来产生新线程。语法)
[线程模块](#线程模块)
[使用 threading 模块创建线程](#使用 threading 模块创建线程)
[线程同步](#线程同步)
[线程优先级队列( Queue)](#线程优先级队列( Queue))
[Queue 模块中的常用方法:](#Queue 模块中的常用方法:)

<h3 id="线程可以分为:">线程可以分为:</h3>

内核线程
用户线程

[回去](#Python3 多线程)

<h3 id="Python3 线程中常用的两个模块为:">Python3 线程中常用的两个模块为:</h3>

_thread
threading(推荐使用)

[回去](#Python3 多线程)

<h3 id="开始学习Python线程">开始学习Python线程</h3>

[回去](#Python3 多线程)

<h3 id="函数式:调用 _thread 模块中的start_new_thread()函数来产生新线程。语法">函数式:调用 _thread 模块中的start_new_thread()函数来产生新线程。语法</h3>

参数说明:

function
args
kwargs

[回去](#Python3 多线程)

<h3 id="线程模块">线程模块</h3>

[回去](#Python3 多线程)

<h3 id="使用 threading 模块创建线程">使用 threading 模块创建线程</h3>

[回去](#Python3 多线程)

<h3 id="线程同步">线程同步</h3>

[回去](#Python3 多线程)

<h3 id="线程优先级队列( Queue)">线程优先级队列( Queue)</h3>

[回去](#Python3 多线程)

<h3 id="Queue 模块中的常用方法:">Queue 模块中的常用方法:</h3>

Queue.qsize()
Queue.empty()
Queue.full()
Queue.full 与 maxsize
Queue.get([block[, timeout]])
Queue.get_nowait()
Queue.put(item)
Queue.put_nowait(item)
Queue.task_done()
Queue.join()

[回去](#Python3 多线程)


## Python3 XML 解析

<h3 id="Python3 XML 解析">目录</h3>

[什么是 XML?](#什么是 XML?)
[Python 对 XML 的解析](#Python 对 XML 的解析)
[1.SAX (simple API for XML )](#1.SAX (simple API for XML ))
[2.DOM(Document Object Model)](#2.DOM(Document Object Model))
[Python 使用 SAX 解析 xml](#Python 使用 SAX 解析 xml)
[ContentHandler 类方法介绍](#ContentHandler 类方法介绍)
[make_parser 方法](#make_parser 方法)
[parser 方法](#parser 方法)
[parseString 方法](#parseString 方法)
[Python 解析XML实例](#Python 解析XML实例)
[使用xml.dom解析xml](#使用xml.dom解析xml)

<h3 id="什么是 XML?">什么是 XML?</h3>

[回去](#Python3 XML 解析)


<h3 id="Python 对 XML 的解析">Python 对 XML 的解析</h3>

[回去](#Python3 XML 解析)


<h3 id="1.SAX (simple API for XML )">1.SAX (simple API for XML )</h3>

[回去](#Python3 XML 解析)


<h3 id="2.DOM(Document Object Model)">2.DOM(Document Object Model)</h3>

[回去](#Python3 XML 解析)


<h3 id="Python 使用 SAX 解析 xml">Python 使用 SAX 解析 xml</h3>

[回去](#Python3 XML 解析)


<h3 id="ContentHandler 类方法介绍">ContentHandler 类方法介绍</h3>

characters(content) 方法
startDocument() 方法
endDocument() 方法
startElement(name, attrs) 方法
endElement(name) 方法

[回去](#Python3 XML 解析)


<h3 id="make_parser 方法">make_parser 方法</h3>

参数说明:

parser_list

[回去](#Python3 XML 解析)


<h3 id="parser 方法">parser 方法</h3>

参数说明:

xmlfile
contenthandler
errorhandler

[回去](#Python3 XML 解析)


<h3 id="parseString 方法">parseString 方法</h3>

参数说明:

xmlstring
contenthandler
errorhandler

[回去](#Python3 XML 解析)


<h3 id="Python 解析XML实例">Python 解析XML实例</h3>

[回去](#Python3 XML 解析)

<h3 id="使用xml.dom解析xml">使用xml.dom解析xml</h3>

[回去](#Python3 XML 解析)

## Python3 JSON 数据解析

<h3 id="Python3 JSON 数据解析">目录</h3>

[json.dumps()](#json.dumps())
[json.loads()](#json.loads())
[Python 编码为 JSON 类型转换对应表:](#Python 编码为 JSON 类型转换对应表:)
[JSON 解码为 Python 类型转换对应表:](#JSON 解码为 Python 类型转换对应表:)
[json.dumps 与 json.loads 实例](#json.dumps 与 json.loads 实例)

<h3 id="json.dumps()">json.dumps()</h3>

[回去](#Python3 JSON 数据解析)

<h3 id="json.loads()">json.loads()</h3>

[回去](#Python3 JSON 数据解析)

<h3 id="Python 编码为 JSON 类型转换对应表:">Python 编码为 JSON 类型转换对应表:</h3>

dict
list, tuple
str
int, float, int- & float-derived Enums
True
False
None

[回去](#Python3 JSON 数据解析)


<h3 id="JSON 解码为 Python 类型转换对应表:">JSON 解码为 Python 类型转换对应表:</h3>

object
array
string
number (int)
number (real)
true
false
null

[回去](#Python3 JSON 数据解析)

<h3 id="json.dumps 与 json.loads 实例">json.dumps 与 json.loads 实例</h3>

[回去](#Python3 JSON 数据解析)

## Python3 日期和时间

<h3 id="Python3 日期和时间">目录</h3>

[什么是时间元组?](#什么是时间元组?)
[获取当前时间](#获取当前时间)
[获取格式化的时间](#获取格式化的时间)
[格式化日期](#格式化日期)
[python中时间日期格式化符号:](#python中时间日期格式化符号:)
[获取某月日历](#获取某月日历)
[Time 模块](#Time 模块)
[Time模块包含了以下2个非常重要的属性:](#Time模块包含了以下2个非常重要的属性:)
[日历(Calendar)模块](#日历(Calendar)模块)

<h3 id="什么是时间元组?">什么是时间元组?</h3>

[回去](#Python3 日期和时间)

<h3 id="获取当前时间">获取当前时间</h3>

[回去](#Python3 日期和时间)

<h3 id="获取格式化的时间">获取格式化的时间</h3>

[回去](#Python3 日期和时间)

<h3 id="格式化日期">格式化日期</h3>

%y
%Y
%m
%d
%H
%I
%M
%S
%a
%A
%b
%B
%c
%j
%p
%U
%w
%W
%x
%X
%Z
%%

[回去](#Python3 日期和时间)

<h3 id="获取某月日历">获取某月日历</h3>

[回去](#Python3 日期和时间)

<h3 id="Time 模块">Time 模块</h3>

time.altzone
time.asctime([tupletime])
time.clock()
time.ctime([secs])
time.gmtime([secs])
time.localtime([secs]
time.mktime(tupletime)
time.sleep(secs)
time.strftime(fmt[,tupletime])
time.strptime(str,fmt='%a %b %d %H:%M:%S %Y')
time.time( )
time.tzset()
time.perf_counter()
time.process_time()

[回去](#Python3 日期和时间)

<h3 id="Time模块包含了以下2个非常重要的属性:">Time模块包含了以下2个非常重要的属性:</h3>

time.timezone
time.tzname

[回去](#Python3 日期和时间)

<h3 id="日历(Calendar)模块">日历(Calendar)模块</h3>

calendar.calendar(year,w=2,l=1,c=6)
calendar.firstweekday( )
calendar.isleap(year)
calendar.leapdays(y1,y2)
calendar.month(year,month,w=2,l=1)
calendar.monthcalendar(year,month)
calendar.monthrange(year,month)
calendar.prcal(year,w=2,l=1,c=6)
calendar.prmonth(year,month,w=2,l=1)
calendar.setfirstweekday(weekday)
calendar.timegm(tupletime)
calendar.weekday(year,month,day)

[回去](#Python3 日期和时间)

## Python MongoDB

<h3 id="Python MongoDB">目录</h3>

[PyMongo](#PyMongo)
[pip 安装](#pip 安装)
[easy_install 安装](#easy_install 安装)
[测试 PyMongo](#测试 PyMongo)
[创建数据库](#创建数据库)
[判断数据库是否已存在](#判断数据库是否已存在)
[创建集合](#创建集合)
[判断集合是否已存在](#判断集合是否已存在)
[增、删、改、查等操作](#增、删、改、查等操作)
[添加数据](#添加数据)
[查询数据](#查询数据)
[修改数据](#修改数据)
[数据排序](#数据排序)
[删除数据](#删除数据)

<h3 id="PyMongo">PyMongo</h3>

[回去](#Python MongoDB)

<h3 id="pip 安装">pip 安装</h3>

安装 pymongo:
也可以指定安装的版本:
更新 pymongo 命令:

[回去](#Python MongoDB)

<h3 id="easy_install 安装">easy_install 安装</h3>

旧版的 Python 可以使用 easy_install 来安装,easy_install 也是 Python 包管理工具
更新 pymongo 命令:

[回去](#Python MongoDB)

<h3 id="测试 PyMongo">测试 PyMongo</h3>

[回去](#Python MongoDB)

<h3 id="创建数据库">创建数据库</h3>

[回去](#Python MongoDB)

<h3 id="判断数据库是否已存在">判断数据库是否已存在</h3>

[回去](#Python MongoDB)

<h3 id="创建集合">创建集合</h3>
[回去](#Python MongoDB)

<h3 id="判断集合是否已存在">判断集合是否已存在</h3>

[回去](#Python MongoDB)

<h3 id="增、删、改、查等操作">增、删、改、查等操作</h3>

[回去](#Python MongoDB)

<h3 id="添加数据">添加数据</h3>

插入集合
返回 _id 字段
插入多个文档
插入指定 _id 的多个文档

[回去](#Python MongoDB)

<h3 id="查询数据">查询数据</h3>

查询一条数据
查询集合中所有数据
查询指定字段的数据
根据指定条件查询
高级查询
使用正则表达式查询
返回指定条数记录

[回去](#Python MongoDB)

<h3 id="修改数据">修改数据</h3>

Python Mongodb 修改文档

[回去](#Python MongoDB)

<h3 id="数据排序">数据排序</h3>

排序

[回去](#Python MongoDB)

<h3 id="删除数据">删除数据</h3>

Python Mongodb 删除数据
删除多个文档
删除集合中的所有文档
删除集合

[回去](#Python MongoDB)

## Python uWSGI 安装配置

<h3 id="Python uWSGI 安装配置">目录</h3>

[Python 安装 uWSGI](#Python 安装 uWSGI)
[第一个 WSGI 应用](#第一个 WSGI 应用)
[添加并发和监控](#添加并发和监控)
[结合 Web 服务器使用](#结合 Web 服务器使用)
[部署 Django](#部署 Django)
[部署 Flask](#部署 Flask)

<h3 id="Python 安装 uWSGI">Python 安装 uWSGI</h3>

1、通过 pip 命令:
2、下载安装脚本:
3、源代码安装:

[回去](#Python uWSGI 安装配置)

<h3 id="第一个 WSGI 应用">第一个 WSGI 应用</h3>

[回去](#Python uWSGI 安装配置)

<h3 id="添加并发和监控">添加并发和监控</h3>

[回去](#Python uWSGI 安装配置)

<h3 id="结合 Web 服务器使用">结合 Web 服务器使用</h3>

[回去](#Python uWSGI 安装配置)

<h3 id="部署 Django">部署 Django</h3>

[回去](#Python uWSGI 安装配置)

<h3 id="部署 Flask">部署 Flask</h3>

[回去](#Python uWSGI 安装配置)
posted @ 2020-01-16 19:01  给文明以岁月  阅读(314)  评论(0编辑  收藏  举报