摘要: # 全局变量(global variable)& 非本地局部变量(nonlocal variable)# 关键字global&nonlocal# ===================================================gcount = 0... 阅读全文
posted @ 2018-03-23 15:17 wjc920 阅读(91) 评论(0) 推荐(0) 编辑
摘要: # 过滤器(filter),filter有两个形参,第一个参数返回一个布尔值,# 如果返回True则当前迭代值会被选中,否则不选a = [1, 2, -3, -4, 5, 0.3, -5, 0]print('element in a list:')print(a)#选... 阅读全文
posted @ 2018-03-23 15:16 wjc920 阅读(132) 评论(0) 推荐(0) 编辑
摘要: # 映射函数(map),该函数有至少有两个参数,一个函数类型参数+一个或多个序列,# 序列的个数对应实参函数的形参个数,# 特别注意:# python2中,如果多个序列的长度不同,那么不是最长的序列都会用None补齐# python3中,map会执行到最短的序列耗尽时... 阅读全文
posted @ 2018-03-22 20:28 wjc920 阅读(636) 评论(0) 推荐(0) 编辑
摘要: # 匿名函数(lambda)# ===================================================# 匿名函数部分f = lambda x: x ** 2print('lambda function:')print(f) # a... 阅读全文
posted @ 2018-03-22 20:28 wjc920 阅读(76) 评论(0) 推荐(0) 编辑
摘要: # 装饰器# 主要用于在不改变函数代码的前提下,改变函数的行为,最常见的情况,项目代码日志模块编写# ===================================================# 纯手工打造装饰器def log(func): def ... 阅读全文
posted @ 2018-03-22 20:28 wjc920 阅读(97) 评论(0) 推荐(0) 编辑
摘要: # 迭代器(Iterator)&生成器(generator)# 若要对象可迭代:# 在python2中对象必须包含__iter__(self)和next(self)# 在python3中对象必须包含__iter__(self)和__next__(self)# 其中:_... 阅读全文
posted @ 2018-03-22 20:27 wjc920 阅读(146) 评论(0) 推荐(0) 编辑
摘要: # 函数(function)# python中函数也是对象,可以是函数的参数和返回值# 函数中嵌入函数def sum_square(x): def square_input(x): return x * x return sum([squar... 阅读全文
posted @ 2018-03-22 20:27 wjc920 阅读(99) 评论(0) 推荐(0) 编辑
摘要: # 函数参数# 参数定义的顺序必须是:必选参数、默认参数、可变参数和关键字参数#===================================================# 默认参数,及普通参数在函数调用时的规则def student(name, gend... 阅读全文
posted @ 2018-03-22 20:27 wjc920 阅读(88) 评论(0) 推荐(0) 编辑
摘要: # 列表(list)# 可放不同类型元素# 索引a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]print(a) # range(1, 10)print(a[1]) # 2# 最后一个元素print(a[-1]) # 9# 切片# 所有元素p... 阅读全文
posted @ 2018-03-22 20:26 wjc920 阅读(126) 评论(0) 推荐(0) 编辑
摘要: # 集合(set)# 无序、不重复、可放不同类型元素# 创建非空集合,用{元素序列}a_set = {1, 2, 'a', 'a', 2}print('create a non-empty set:')print(a_set)# 创建空集合不能用{},{}为空dict... 阅读全文
posted @ 2018-03-22 20:26 wjc920 阅读(115) 评论(0) 推荐(0) 编辑