zoukankan      html  css  js  c++  java
  • 内嵌函数

    函数的内嵌即在函数内部定义函数,在内部定义的函数所有的一切都在函数内部,外部无法调用,举例如下:

    >>> def fun1():
        print("fun1()正在被调用。。。")
        def fun2():
          print("fun2()正在被调用。。。")
        fun2()


    >>> fun1()
    fun1()正在被调用。。。
    fun2()正在被调用。。。
    >>> fun2()  #fun2()是在fun1()函数内部创建的,因此在函数外部无法调用
    Traceback (most recent call last):
    File "<pyshell#37>", line 1, in <module>
    fun2()
    NameError: name 'fun2' is not defined

    例1:

    def outside():
      print('I am outside!')
      def inside():
        print('I am inside!')

    inside()

    这里的inside()是无法调用的,正确的方式如下

    def outside():

      print('I am outside!')

      def inside():

        print('I am inside!')

      inside()

    outside()

  • 相关阅读:
    FSL
    64位MicrosoftOfficeWord加载EndnoteX7
    Lobes of the brain
    Anterior and posterior commissures
    Broadmann area (wiki)
    Broadmann分区
    matlab FDR校正
    AI图片剪切
    DPABI advanced edition 文件夹组织形式
    Frequently Asked Questions
  • 原文地址:https://www.cnblogs.com/themost/p/6358944.html
Copyright © 2011-2022 走看看