01月29日【Python3 基础知识】,,01月29日【Pyt
01月29日【Python3 基础知识】,,01月29日【Pyt
01月29日【Python3 基础知识】5.4 参数匿名函数字典排序
5.5 生成式和生成器
5.6 装饰器的作用
5.4 参数匿名函数字典排序
# *元组;**字典def add(*args): total = 0 for i in args: total += i print("total = {0}".format(total))def sortDictValue(dict1): print(sorted(dict1.items(), key =lambda d:d[1], reverse=False))if __name__ == ‘__main__‘: add(1, 2, 3, 4, 5) s1 = lambda x, y: x + y# def s1(x, y):# return x + y print(s1(10, 20)) aaa = dict(a = 100, b = 10, c = 50, d = 321) l = list() sortDictValue(aaa)
5.5 生成式和生成器
了解return和yield的区别
a = [x * x for x in range(1, 30) if x % 2 == 0]print(type(a))b = (x * x for x in range(1, 30) if x % 2 == 0)print(type(b))for i in b: pass# print(i)def test(l): for i in l: yield i print("i = {0}".format(i))m = test([1, 2, 3])print(type(m))for i in m: print(i)
5.6 装饰器的作用
def hello(): print("Hello world")def test(): print("######start######") hello() print("######end######")test()
01月29日【Python3 基础知识】
相关内容
- 深入一步探索Python计算身份证校验位的代码写法【map
- Python [练习题] :字典扁平化,,字典扁平化习题:将以
- python从0到1--01.python中的输入/输出(基础篇),,1.prin
- Python常用第三方库,,Pillow图像处理
- Python基础之方法,,class woma
- python3基础13(format的使用),,#!/usr/bin
- python-xpath定位方法详解,,一、xpath基本定
- 程序员为什么要学python,,如果你做很多在电脑上
- python_面向对象——对象之间的关联关系,,1.将类中的对
- Python时间模块(二)----时间日期格式化符号,,python中时间
评论关闭