python函數名應用

來源:互聯網
上載者:User

標籤:ret   nbsp   容器類   str   資料   ext   括弧   cti   enter   

函數名的應用

函數名 的應用分類:

    函數就是一個特殊的變數(可以看成一個變數來用)
      *函數名對應函數的記憶體位址
      *函數名可以做為容器類資料的元素
      *函數名可以作為函數的參數
      *函數名可以作為函數的傳回值
      *函數名可以隨便賦值。
      向這樣的函數名有一個叫法:第一類函數

1.列印函數名,顯示函數記憶體位址

    舉例:
      # def func1():
      # print(666)
      # print(func1)
    結果:
      # <function func1 at 0x000000000258F9D8>

2 函數名可以作為容器類資料的元素

    舉例:
      def func1():
      print(111)


      def func2():
      print(222)

      def func3():
      print(333)

      l1 = [func1, func2, func3]
      for i in l1:
      i() ####函數名加括弧即執行函數

3 函數名可以作為函數的參數

    舉例:
      def func1():
      print(111)


      def func2(x):
      print(x)
      x()
      print(222)

      func2(func1)

4 函數名可以作為函數的傳回值

    舉例:
      def func1():
      return 111


      def func2(x): # x = func1
      print(222)
      return x

      ret = func2(func1) # func1
      print(ret())
      print(ret)
    結果:
      222
      111
      <function func1 at 0x0215D810>

  說明:
    #向這樣的函數名 有一個叫法 :第一類對象
    Python中包含函數在內的一切皆為對象,函數作為第一類對象,支援賦值給變數,作為參數傳遞給其它函數,作為其它函數的傳回值,支援函數的嵌套,實現了__call__                  方法的類執行個體對象也可以當做函數被調用。

python函數名應用

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.