Python中yield和return两者之间区别

        在任何函数都有返回值,一般都是想到return 关键词,在函数生成器中有个关键词 yield 也可以做返回值,在函数没调用之前,是不会输出任何东西的

 1,return 用法

      def stu():

    return 'hello'

      stu()

 2,yield用法

     def stu():

              a,b=1,1

              b=a+1             

    yield b

    return 'hello'

      stu()

文章来自 http://www.96net.com.cn/

posted @ 2018-09-28 11:56  学无边涯  阅读(1515)  评论(0编辑  收藏  举报