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/

猜你喜欢

转载自www.cnblogs.com/96net/p/9717830.html