![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python学习
帆的孤独啊
这个作者很懒,什么都没留下…
展开
-
python基础知识相关(数据结构 )
list,tuple都是线性表,从0开始按序索引,或者从最后一个-1开始向前索引。list元素可变,tuple不可变。但是tuple内嵌套定义的list中元素可变。list可以使用append(),pop(),insert(),只有1个元素的tuple定义时必须加一个逗号,来消除歧义。 dict即dictionary,类似map,以<键,值>存储 set即集合,同s...原创 2018-05-21 20:32:06 · 112 阅读 · 0 评论 -
python 列举文件下所有文件(子文件夹)
采用os.walk + 递归方式:输出的path数组 即记录了所有文件夹的os.walk(dirname) 返回 root(文件夹所在位置的绝对路径)、dirs(子文件夹的名字)、files(文件的名字)import osrootdir = os.getcwd()path = []def iter_files(rootDir): for root, dirs, fi...原创 2019-03-10 19:39:21 · 708 阅读 · 0 评论 -
python 处理excel
import xlrd, xlwtdef isnum(str): c = str[0] return c == '<' or c == '>' or (c >= '0' and c<='9')def sub(): readbook = xlrd.open_workbook(r'pji.xls') writebook = xlwt...原创 2019-02-16 18:35:35 · 133 阅读 · 0 评论 -
广播机制
import torchfrom torch import nnimport cv2from torchvision.transforms import ToTensor, ToPILImageimport numpy as npclass Linear(nn.Module): def __init__(self, in_features, out_features): ...原创 2018-12-31 16:33:47 · 202 阅读 · 0 评论 -
sympy python 符号运算包
from sympy import *from sympy.plotting import plot3dx, y = symbols('x y')f = Function('f')gasu = 1/sqrt(2*pi) * exp(-0.5 * (x**2 + y**2))#plot3d(gasu, (x, -5, 5), (y, -5, 5))gasu2 = diff(gasu...原创 2019-01-04 19:48:41 · 772 阅读 · 0 评论 -
python多重继承
class D(object): passclass C(D): passclass B(D): passclass A(B, C): pass'''MRO method resolution order 方法解析顺序 为了解决多继承问题 在inspect文件中采用AOV图,每次输出一个入度为零的点(相当于没有人继承自他)super 也是一个...原创 2018-11-02 14:22:49 · 115 阅读 · 0 评论 -
正则表达式
正则表达式是按一定模式匹配特定字符串(所有有意义特殊字符都要以\转义)1.基本操作\d 匹配数字(decimal) \w(word)字母或数字,不包括特殊字符. 匹配任意字符 *任意字符(含0个) +至少一个字符? 0或1个字符 {n}n个字符 {n-m}表示n-m个字符注意以上*+?等加在一个字符后面 特殊情况: r'^(\d...原创 2018-05-28 20:53:29 · 125 阅读 · 0 评论 -
python错误捕捉
python使用try except捕捉错误,当发现错误时无需从底层向上依次返回错误代码,而是直接抛出异常。通常使用方法;try:执行语句,发生错误时后续语句不在执行,转至exceptexcept : 处理该类型的错误except :else: 无错误发生时执行此处finally: 不管有无错误都会执行错误类型见:https://docs.python.org/3/library/except...原创 2018-05-28 19:52:47 · 1022 阅读 · 0 评论 -
python中面向对象
python不需要预定义变量,因此在类内部属性中用到就使用,无需提前定义,类名后object表示继承自它:class Student(object): def __init__(self, name, score): self.__name = name self.__score = score def prints(self): ...原创 2018-05-28 16:42:07 · 134 阅读 · 0 评论 -
补充生成器(yield用法)
加入yield 关键字函数变为generator,执行next遇到yield中断返回值from functools import reducedef odd(): print('step1') yield 1 print('step2') yield 2 print('step3') yield 3def fib(max): n, a,...原创 2018-05-22 20:34:34 · 246 阅读 · 0 评论 -
高级函数
变量可指向函数,并通过变量调用。函数也可作为参数传入另一个函数def sums(a,b,f): return f(a)+f(b)print(sums(1,-2,abs))map:可认为是一种映射,把key映射为valuedef f(x): return x*xa=map(f,list(range(5))) #返回Iteratorprint(list(a))#[0, 1,...原创 2018-05-22 20:25:49 · 1691 阅读 · 0 评论 -
python常用操作
切片: list[首:末:步长]python循环利用可迭代对象from collections import Iterableprint(isinstance('abc',Iterable)) 列表生成式eg: list(range(10)) list(元素 for 元素 in 可迭代对象)L1 = ['Hello', 'World', 18, 'Apple', Non...原创 2018-05-22 16:17:58 · 118 阅读 · 0 评论 -
函数
定义方法def 函数名(参数名,可以有多个,以逗号隔开): 执行语句(执行语句为空时可写pass,不能省) return value(无返回值为return None ,None可省略,在命令行中None不显示,返回值可以有多个,以逗号隔开,实际是tuple格式返回)eg:def f(x,y): return x+y,x-yprint(f(1,2))使用默认参数,当不按默认顺...原创 2018-05-21 21:34:18 · 226 阅读 · 0 评论 -
python 装饰器
def deco(fun): # 这里用闭包函数的原因 闭包函数可以拿到fun变量 同时warpper又能接受参数 def wrapper(*args, **kwargs): print("decorate begin") print(args) #(1, 2) print(kwargs) # {} # 这...原创 2019-06-24 16:36:04 · 96 阅读 · 0 评论