前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >01月29日【Python3 基础知识】

01月29日【Python3 基础知识】

作者头像
py3study
发布2020-01-06 15:03:55
2270
发布2020-01-06 15:03:55
举报
文章被收录于专栏:python3python3

01月29日【Python3 基础知识】

5.4 参数匿名函数字典排序 5.5 生成式和生成器 5.6 装饰器的作用

5.4 参数匿名函数字典排序

代码语言:javascript
复制
# *元组;**字典
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的区别
代码语言:javascript
复制
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 装饰器的作用

代码语言:javascript
复制
def hello():
    print("Hello world")
def test():
    print("######start######")
    hello()
    print("######end######")
test()
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-09-25 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 01月29日【Python3 基础知识】
    • 5.4 参数匿名函数字典排序
      • 5.5 生成式和生成器
        • 5.6 装饰器的作用
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档