<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國際加速解決方案。 廣告
                # 運行 python 程序 > 原文: [https://thepythonguru.com/running-python-programs/](https://thepythonguru.com/running-python-programs/) * * * 于 2020 年 1 月 7 日更新 * * * 您可以通過兩種方式運行 python 程序,首先通過直接在 python shell 中鍵入命令或運行存儲在文件中的程序。 但是大多數時候您想運行存儲在文件中的程序。 讓我們在記事本目錄中創建一個名為`hello.py`的文件,即使用記事本(或您選擇的任何其他文本編輯器)創建一個`C:\Users\YourUserName\Documents`,記住 python 文件具有`.py`擴展名,然后在文件中編寫以下代碼。 ```py print("Hello World") ``` 在 python 中,我們使用`print`函數將字符串顯示到控制臺。 它可以接受多個參數。 當傳遞兩個或多個參數時,`print()`函數顯示每個參數,并用空格分隔。 ```py print("Hello", "World") ``` **預期輸出**: ```py Hello World ``` 現在打開終端,并使用`cd`命令將當前工作目錄更改為`C:\Users\YourUserName\Documents`。 ![CHANGE-CURRENT-WORKING-DIRECTORY.png](https://img.kancloud.cn/85/11/8511397f7ba1d324f51f345d4b3c4733_722x93.png) 要運行該程序,請鍵入以下命令。 ```py python hello.py ``` ![RUNNING-HELLO-WORLD-PROGRAM.png](https://img.kancloud.cn/8c/b5/8cb58705aac32543c5c5933e7abf87c9_722x146.png) 如果一切順利,您將獲得以下輸出。 ```py Hello World ``` ## 獲得幫助 * * * 使用 python 遲早會遇到一種情況,您想了解更多有關某些方法或函數的信息。 為了幫助您,Python 具有`help()`函數,這是如何使用它。 **語法**: 要查找有關類別的信息:`help(class_name)` 要查找有關方法的更多信息,屬于類別:`help(class_name.method_name)` 假設您想了解更多關于`int`類的信息,請轉到 Python shell 并鍵入以下命令。 ```py >>> help(int) Help on class int in module builtins: class int(object) | int(x=0) -> integer | int(x, base=10) -> integer | | Convert a number or string to an integer, or return 0 if no arguments | are given. If x is a number, return x.__int__(). For floating point | numbers, this truncates towards zero. | | If x is not a number or if base is given, then x must be a string, | bytes, or bytearray instance representing an integer literal in the | given base. The literal can be preceded by '+' or '-' and be surrounded | by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. | Base 0 means to interpret the base from the string as an integer literal. | >>> int('0b100', base=0) | 4 | | Methods defined here: | | __abs__(self, /) | abs(self) | | __add__(self, value, /) | Return self+value. ``` 如您所見,`help()`函數使用所有方法吐出整個`int`類,它還在需要的地方包含說明。 現在,假設您想知道`str`類的`index()`方法所需的參數,要找出您需要在 python shell 中鍵入以下命令。 ```py >>> help(str.index) Help on method_descriptor: index(...) S.index(sub[, start[, end]]) -> int Like S.find() but raise ValueError when the substring is not found. ``` 在下一篇文章中,我們將學習 python 中的數據類型和變量。 * * * * * *
                  <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>

                              哎呀哎呀视频在线观看