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))

        

  • 相关阅读:
    JS年月日三级联动下拉列表
    日志分析软件
    配置Smarty
    JS无刷新省市两级联动下拉列表
    graylog2+syslogng+mongodb构建集中管理日志服务器
    syslog及syslogng详解
    php+pdo实现分页类代码
    编程实践62
    编程实践65
    编程实践64
  • 原文地址:https://www.cnblogs.com/zhouA/p/14480944.html
Copyright © 2011-2022 走看看