摘要: # class Test(object): # def __call__(self): # print(' test ') # t= Test()# t() 调用主要有个__call__方法 # __new__ __init__ __del__ __str__ __slots__ __call__ 阅读全文
posted @ 2018-08-09 15:28 红尘陌上,独自行走 阅读(154) 评论(0) 推荐(0) 编辑
摘要: # 以c语言为主是静态语言,运行之前先编译,在运行的过程中不允许编辑代码# 在运行的过程中,可以改变,可以添加属性,就是属于动态语言(python) # python动态的添加属性以及方法class Test(object): pass # t = Test()# print(dir(t)) # 运 阅读全文
posted @ 2018-08-09 12:13 红尘陌上,独自行走 阅读(642) 评论(0) 推荐(0) 编辑
摘要: 什么是命名空间 == 对一个名字起作用的范围 # def test():# print(" test ") # import test# test.test() # from test import * # LEGB规则 locals > enclosing function > globals > 阅读全文
posted @ 2018-08-09 11:44 红尘陌上,独自行走 阅读(86) 评论(0) 推荐(0) 编辑
摘要: # 使用装饰器对有返回值的函数进行装饰# def func(functionName): # print(' func-1 ') # def func_in(): # print(" func_in 1-") # x = functionName() #保存返回来的hahah # print(" f 阅读全文
posted @ 2018-08-09 11:23 红尘陌上,独自行走 阅读(174) 评论(0) 推荐(0) 编辑
摘要: # 使用装饰器无参数的函数进行装饰# def func(funcionName): # print(' 1 ') # def func_in(): # print('--func_in ') # funcionName() # print('--func_2 ') # print(' 2 ') # 阅读全文
posted @ 2018-08-09 10:04 红尘陌上,独自行走 阅读(133) 评论(0) 推荐(0) 编辑
摘要: # 装饰器,对一个函数打扮 # def foo():# print("foo")# foo# foo()# def test1():# print(' 1 ')# def test1():# print(' 2 ')# test1() # 需求来了 # 开放封闭规则# 封闭:以实现的功能代码块# 开 阅读全文
posted @ 2018-08-08 17:52 红尘陌上,独自行走 阅读(104) 评论(0) 推荐(0) 编辑
摘要: def test(): # 函数名中的test相当于一个变量名 print(' 1 ') # test() #调用这个函数 1 # # test #test指向了一个函数块,变量名指向了函数体 # print(test) # <function test at 0x000002BD550C7F28> 阅读全文
posted @ 2018-08-08 12:07 红尘陌上,独自行走 阅读(90) 评论(0) 推荐(0) 编辑
摘要: # 迭代器 # 迭代==再上一个版本的基础上,在更新一个版本 # 可迭代对象# 以直接作用于for循环的数据类型有以下几种:# 一类是集合数据类型: 如 list 、tuple、dict、set、str等# 一类是generator,包括生成器和带yield的generator function。# 阅读全文
posted @ 2018-08-08 10:44 红尘陌上,独自行走 阅读(82) 评论(0) 推荐(0) 编辑
摘要: # 生成器 a = [x*2 for x in range(10)]print(a) # 通过生成器,生成你想要的列表,# 等你什么时候用,什么时候生成 # 生成器的第一种表现形式 () b = (x*2 for x in range(10))# print(next(b))# print(next 阅读全文
posted @ 2018-08-07 20:47 红尘陌上,独自行走 阅读(119) 评论(0) 推荐(0) 编辑
摘要: # 1.浅拷贝(复制东西)a = [11,22,33] # 实际上是浅拷贝# 没有把这个变量的值赋进去,而是把另一个变量的地址拿过去了,就叫浅拷贝。b = a # print(id(a))# print(id(b)) # 什么是深拷贝import copyc = copy.deepcopy(a) # 阅读全文
posted @ 2018-08-07 16:08 红尘陌上,独自行走 阅读(92) 评论(0) 推荐(0) 编辑