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

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 變量 > 原文: [https://pythonbasics.org/variables/](https://pythonbasics.org/variables/) Python 支持不同類型的變量(數據類型),例如整數,浮點數和文本。 您無需指定變量的數據類型,只需將任何值分配給變量即可。 在下面鍵入程序并啟動它。 ## 數據類型 變量可以是幾種數據類型。 Python 支持整數(數字),浮點數,布爾值(對或錯)和字符串(文本)。 Python 將根據您分配給變量的值來確定數據類型。 如果創建變量`x`,`x = 3`,則 Python 假定其為整數。 但是,如果您指定`x = 1.5`,則 Python 知道其不是整數,而是浮點數。 ## 示例 下面的示例向您展示了幾個變量。 這些可以根據需要分配。 定義后,您可以打印它們或使用算術。 ```py #!/usr/bin/python x = 3 # a whole number f = 3.1415926 # a floating point number name = "Python" # a string print(x) print(f) print(name) combination = name + " " + name print(combination) sum = f + f print(sum) ``` 從終端或使用 IDE 運行程序。 ```py python example.py ``` 在示例中,我們有幾個變量(`x`,`f`,`name`),它們具有不同的數據類型。 在程序的后面,我們創建更多的變量(`combination`,`sum`)。 可以在程序中的任何位置定義變量。 變量名可以是 1 到 n 個字母。 您應該看到幾行包含數字和文本的行: ![python variables](https://img.kancloud.cn/9c/c6/9cc6fd072c8b69716d5c31a48da2255b_782x469.jpg) ### 命名 變量名必須以字母(大寫或小寫)或下劃線開頭。 變量不能以數字開頭,并且區分大小寫。 如果創建兩個變量`x`和`X`,則它們是不同的變量。 ```py Python 3.5.3 (default, Jan 19 2017, 14:11:04) [GCC 6.3.0 20170118] on linux Type "help", "copyright", "credits" or "license" for more information. >>> x = 3 >>> X = 4 >>> print(x) 3 >>> print(X) 4 >>> ``` ### 駝峰大小寫 按照慣例,變量通常用駝峰大小寫,這意味著第一個字母較小,接下來的單詞全為大寫。 一些使用駝峰大小寫的示例變量 ```py daysInYear = 365 daysInMonth = 30 numberFiles = 5 ``` 這比擁有一個長變量(`dayinyear`)更容易閱讀。 但這不是 Python 的嚴格要求。 ## 練習 試試下面的練習 1. 制作一個顯示幾個數字的程序。 2. 編寫一個程序來解決并顯示`64 + 32`的總和。 3. 進行與 2 中相同的操作,但將其計算`x + y`。 完成這些步驟后,繼續下一個練習。 [下載示例](https://gum.co/dcsp)
                  <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>

                              哎呀哎呀视频在线观看