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

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 寫入文件 > 原文: [https://pythonbasics.org/write-file/](https://pythonbasics.org/write-file/) 寫入文件功能是標準模塊的一部分,您無需包含任何模塊。 寫入和附加到文件在 Python 語言中是不同的。您可以使用這行打開要寫入的文件: ```py f = open("test.txt","w") ``` 附加到文件中使用: ```py f = open("test.txt","a") ``` 如果指定了錯誤的參數,則文件可能被清空! ## 示例 ### 創建新文件 要創建新文件,可以使用以下代碼: ```py #!/usr/bin/env python # create and open file f = open("test.txt","w") # write data to file f.write("Hello World, \n") f.write("This data will be written to the file.") # close file f.close() ``` `"\n"`字符添加新行。 如果文件已經存在,則將其替換。 如果使用`"w"`參數,則文件的現有內容將被刪除。 ### 附加到文件 要將文本添加到文件末尾,請使用`"a"`參數。 ```py #!/usr/bin/env python # create and open file f = open("test.txt","a") # write data to file f.write("Don't delete existing data \n") f.write("Add this to the existing file.") # close file f.close() ``` ## 練習 1. 將文本“輕松”寫到文件中 2. 將`open("text.txt")`行寫入文件 [下載示例](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>

                              哎呀哎呀视频在线观看