<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                [TOC] >[success] # 函數的使用 >[danger] ##### 經典的 *args 和**kwargs ~~~ 1.*arg 代表的是元祖 2.** kwargs 代表是字典 接受的a = b 這種形式參數變成字典,這里面接受字典不是指的是傳的{字典} ~~~ >[danger] ##### 案例 ~~~ def arg(first, *args, **kwargs): print(first,args,kwargs) arg(1, 2, 3, 4) arg(1, [2, 3, 4]) arg(1, {"a": 1, "b": 21}) arg(1, a=1) 打印結果: 1 (2, 3, 4) {} 1 ([2, 3, 4],) {} 1 ({'a': 1, 'b': 21},) {} 1 () {'a': 1} ~~~ >[danger] ##### 也可以返回多個值,是元祖類型 ~~~ def arg(first, *args, **kwargs): return first,args,kwargs print(arg(1,2,c=3)) 打印結果: (1, (2,), {'c': 3}) ~~~ >[danger] ##### 不傳遞任何值和傳遞None的區別 * 不傳遞任何值 ~~~ # 定一個私有變量 _no_value = object() def spam(a, b=_no_value): if b is not _no_value: print(1) ~~~ * 定義一個傳入為None ,目前我認為兩者區別前者更謹慎 ~~~ def spam(a, b=None): if b is not None: print(1) ~~~ * 超級錯誤寫法,如果b 是一些0 Flase 本身一些表述錯誤的,這段代碼運行就會有問題 ~~~ def spam(a, b=None): if not b: print(1) ~~~ >[danger] ##### 使用初始化變量禁忌 ~~~ 1.不用去使用 那些可變的變量例如[] ~~~ * 錯誤示范 ~~~ # 錯誤示范 def a(a,b=[]) ~~~ >[danger] ##### 關于定義默認函數的參數問題 ~~~ 1.不建議下面的這種使用,因為變量聲明是在,函數創建的時候就已經聲明完畢 2.所以不會因為那你 調用的時候重新定義變量,結果發生改變 ~~~ ~~~ z = 10 def a(x, y=z): print(x, y) a(1) z = 20 a(1) 打印結果: 10 10 ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看