Python
文章平均质量分 78
zz强仔zz
程序猿
展开
-
9、Python_生成式、生成器
1、列表生成式:list = [x*x for x in range(1,88) if x%2==0]4,16,36,。。。。。后边可以加if条件过滤 2、生成器:用法一-》g = (x*x for x in range(1,88) if x%2==0)直接 使用next(g)即可获取生成器生成的元素在生成式上略作修改,将[]改成()即可上述g是一个gene...原创 2018-06-30 11:15:03 · 126 阅读 · 0 评论 -
12、Python_匿名函数
1、lambda 使用原来函数:def ia_odd(n): return n%2 == 1L = list(filter(is_odd, range(1, 20)))print(L) 使用匿名函数代替:is_odd = lambda x:x%2==1L = list(filter(is_odd, range(1, 20)))print(L)...原创 2019-01-09 18:13:57 · 125 阅读 · 0 评论 -
11、Pyhon_返回函数
1、函数作为返回值:求和函数:def calc_sum(*args): ax = 0 for n in args: ax = ax +n return ax但不想立刻返回,可以这样写:def lazy_sum(*args): def sum(): ax = 0 for n in args:...原创 2019-01-07 17:27:14 · 91 阅读 · 0 评论 -
16、Python_面向对象高级
1、使用__slots__限制属性:class Student(object): pass s= Student()s.name="Jack" def set_name(self,name): self.name=name from types import MethodTypes.set_name=MethodType(set_name,s...原创 2019-01-17 17:59:00 · 102 阅读 · 0 评论 -
15、Python_面向对象
1、私有变量:object.__age;//两条杠,外部无法访问,但要访问还是可以用_object.__age访问object._age;//一条杠,当成私有变量 2、特殊变量:object.__age__;//前后都有两条杠 3、继承与多态:def run(object): pass 调用时:run(Cat())run(Dog())r...原创 2019-01-17 17:20:10 · 137 阅读 · 0 评论 -
14、Python_模块
1、模块结构src->bug->outofbounds.py、nullpoint.py、math.pysrc->goods->book.py、cup.py如上路径,src即为package,下边有两子package bug and goods注意:package下边必须要有__init__.py文件,以区分这是一个package而不是一个普通文件夹 ...原创 2019-01-11 18:33:31 · 87 阅读 · 0 评论 -
13、Python_装饰器、偏函数
装饰器--》原函数:def now(): print("2019-01-10")print(now._name_) 增加原函数的功能:def log(func): def wrapper(*args,**kw): print("call %s():" %func._name_) return func(*args,**...原创 2019-01-10 18:27:02 · 66 阅读 · 0 评论 -
10、Python_高阶函数map/reduce/filter/sorted
1、map的使用:map()函数可以把传入的函数作用到传入的Iterable中的每一个元素。例:f(x)=x2(平方),要把这个函数作用在一个list[1,2,3,4,5,6,7,8,9]def f(x): return x*xr=map(f,[1,2,3,4,5,6,7,8,9]) 2、reduce的用法:reduce把一个函数作用在一个序列[x1, x2,...原创 2018-12-25 11:38:44 · 164 阅读 · 0 评论 -
5、Python_dict/set
Dict1、dict 具象了解? 答:就是一本字典,可以快速查找,使用key-value存储 2、dict 技术实现细节? 答:有成绩字典score = {'Jack':100,'Rose':60},然后查Jack的成绩为score['Jack'] 3、dict 增、改、查、删? 答:增--》score['John'] = 100 ...原创 2018-12-19 11:21:21 · 114 阅读 · 0 评论 -
4、Python_条件判断(if else input)与循环
1、对比java语言中if/elsejava:if(true){}else{} python:if True: print("this is true code")else if False: print("this is false code")else: print("this is dead code") 2、birt...原创 2018-12-18 16:02:41 · 314 阅读 · 0 评论 -
8、Python_list/tuple切片&迭代
1、背景:list=["jack","lucky","john","petter","rose"]取list或tuple一部分元素时,一个一个取很麻烦,于是就有了切片。 2、如何使用切片?list[0:3]--------->从索引0到索引3位置的元素(不包括索引3位置元素)["jack","lucky","john"原创 2018-12-21 14:32:41 · 278 阅读 · 0 评论 -
6、Python_函数调用与定义
1、基本常用函数: abs(100)---->绝对值 max(1,2)---->取大值 int('123') ---->类型转换 float('123') ---->类型转换 str(123) ---->类型转换 bool(1) ---->类型转换 hex(18)---->十进制转十六进...原创 2018-12-20 18:00:33 · 179 阅读 · 0 评论 -
7、Python_函数参数,可变参数与关键字参数
1、可变参数:定义-》def fun(name,sex,*c) pass调用-》fun(jack,male,16,helloworld)可以传多个参数 把list或tuple传入:list=['jackpeng','roseli']fun(jack,male,16,*list) 2、关键字参数:定义-》def fun(name,sex,**...原创 2018-07-03 15:00:05 · 138 阅读 · 0 评论 -
2、Python_字符串与编码
1、字节、byte知识一个字节8位,用来表示一个字符1byte = 8bit 二进制11111111 = 十进制255 2、编码知识计算机是美国人发明,所以最早只有127个字符被编码到计算机。SCII码: 0-127 (中文肯定不够用)GB2312码:中文Shift_JIS码:日文Euc-kr码:韩国Unicode码:把所有语言都统一到一套编码中UT...原创 2018-06-19 15:54:44 · 186 阅读 · 0 评论 -
1、Python_入门简介
1、背景 近10年常用编译语言:C、Java、C++、PHP、C#、Python、Object-C、(Visual)Basic、Transact-SQL、JavaScript。 2、优缺点C:接近底层,运行速度快,性能好;Python:基础代码库丰富,大量第三方库,效率低,运行速度慢,代码不能加密,只能发布源码; 3、Python适用范围网络应用、日常小工具,脚...原创 2018-06-19 11:17:40 · 128 阅读 · 0 评论 -
3、Python_数据结构(list/tuple)
List:元素可变,用[]list=[1,2,3,4,5,6,7,8]获取长度:len(list)---------->8获取元素:list[0]--------->1获取最后一个元素:list[7]或list[-1]------------>8获取倒数第2个元素:list[-2]----------->7 添加元素到末尾:list.append...原创 2018-06-30 11:38:50 · 177 阅读 · 0 评论 -
17、Python_多进程与通信
多进程主要应用的两个操作系统上的区别Linux可以通过fork()函数创建子进程子进程返回0父进程返回子进程的id代码:import ospid=os.fork()if pid==0: #这里是子进程跑的逻辑else: #这里是子进程跑的逻辑Windowswindows上没有fork调用但可以使用multiprocessing模块代码:from multi...原创 2019-03-14 16:16:15 · 84 阅读 · 0 评论