zoukankan      html  css  js  c++  java
  • 06.Python基础--函数深入

    函数语法组合结构:

    并列函数类型:

    def func1(x,y=3):

      sum = x+y

      return sum

    def func2(x,y):

      s = x*y

      return s

    def func3(x,y):

      ss = x+y

      return ss

    if __name__ == '__main__':

      a = func1(1,y=2)  #a用来接收func1的返回值

      b = func2(a,2)  # 将func1的返回值a作为参数传入func2中

      c = func3(a,b)  # 将func1的返回值a和func2的返回值b作为参数传入func3中

    包含函数类型&函数作用域

    def func(a,b,c):

      def test1(x):

        y = 2*x + 1

        return y

      line = test(a)

      print(line)

      def test2(x):

        y = 2*x + 1

        return y

      line = test(b)

      print(line)

      def test3(x):

        y = 2*x + 1

        return y

      line = test(c)

      print(line)

    func(1,2,3)

    print(test(1))  #这里将会显示未定义,超出了函数的作用域

    闭包:

     函数是一个对象,所以可以作为某个函数的返回结果

    def func():

      def test1(x):

        return 2*x + 1

      return test1

    my_func = func()

    print(my_func(3))

        

  • 相关阅读:
    Java运行时内存
    java --对象流与对象的序列化
    Java 文件操作
    爬虫
    eclipse项目放到github
    越来越玄的JAVA
    map和set的遍历
    集合总览
    unsafe类
    狡诈的java并发容器
  • 原文地址:https://www.cnblogs.com/zhouA/p/14480944.html
Copyright © 2011-2022 走看看