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

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # 字符串 > 原文: [https://pythonbasics.org/strings/](https://pythonbasics.org/strings/) 每當您想在 Python 中使用文本時,都在使用字符串。 如果您使用雙引號,Python 會理解您要使用字符串。 創建字符串后,您可以直接直接打印字符串變量。 您可以使用方括號訪問字符。 ## 字符串 ### 定義字符串 變量可以是字符串數據類型。 它們可以容納字符或文本。如果創建字符串變量`x`。 您可以使用`print()`函數在屏幕上顯示它。 ```py x = "Hello" print(x) ``` ### 字符串索引 可以使用方括號訪問各個字符,計數從零開始。 ```py print(x[0]) print(x[1]) ``` 第一個字符從零開始。 這可能有點反常,但有歷史原因。 ### 子字符串 通過使用冒號,您可以創建一個子字符串。 如果沒有寫開始或結束編號,Python 會假定您是第一個字符或最后一個字符。 請嘗試以下示例: ```py x = "hello world" s = x[0:3] print(s) s = x[:3] print(s) ``` ### 完整的示例 這個例子做了很多字符串操作,例如打印文本,數字,組合字符串,切片和訪問元素。 請嘗試以下程序: ```py x = "Nancy" print(x) # Combine numbers and text s = "My lucky number is %d, what is yours?" % 7 print(s) # alternative method of combining numbers and text s = "My lucky number is " + str(7) + ", what is yours?" print(s) # print character by index print(x[0]) # print piece of string print(x[0:3]) ``` 您應該看到以下輸出: ![python strings](https://img.kancloud.cn/ac/5a/ac5a95535ca887986ae0edf0b6d9f38b_796x443.jpg) ## 練習 試試下面的練習 1. 制作一個顯示您喜歡的演員的程序。 2. 嘗試在`s`中打印`"lucky"`一詞。 3. 嘗試以“今天是 2/2/2016”的格式打印日,月,年。 [下載示例](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>

                              哎呀哎呀视频在线观看