<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、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                Python 是 Guido van Rossum(龜叔,荷蘭人)于1989年圣誕期間為打發無聊的時間而開發的一門解釋型腳本語言。1991年第一次發行。Python 發行版本信息:[https://www.python.org/downloads/](https://www.python.org/downloads/) ***** [TOC] ***** # 1.1 準備開始 **安裝 Python** 目前 Python 有兩個大版本:Python 3.x 和 Python 2.x。2.x版本將于2020年停止安全更新。初學者直接學習 Python 3.x 版本即可。 要編寫 Python 程序,需要先安裝 Python 解釋器等,請到 [Python官網](https://www.python.org/downloads/) 下載最新版本 Python 進行安裝,根據你的操作系統進行選擇。 安裝完成后,打開你的電腦終端(Terminal),輸入如下命令以**驗證 Python 是否安裝成功**: ```bash $ python --version ``` > Windows 系統,需將 Python 安裝路徑以及腳本(Scripts)路徑添加到系統環境變量 如果安裝成功,終端(Terminal)將輸出 Python 安裝版本信息(下列信息僅供參考): ```bash $ python --version Python 3.7.0 ``` **編寫你的第一個 Python 程序** 就像寫文檔需要用到 Office Word,我們編寫 Python 程序也需要一個專門的軟件,剛開始學我們只需要使用 Python 自帶的編輯器 [IDLE](https://docs.python.org/2/library/idle.html) 即可。 安裝 Python 之后,你的系統中就安裝好了 IDLE。 在不同系統中打開 IDLE: * 在 Windos 系統中,在所有程序中找到它,打開它 * 在基于 Unix 的系統中,可在終端輸入`$ idle python_file.py` 來打開它 打開 IDLE 后,我們將進入一個交互式界面,在這個界面中我們可以一行一行的輸入代碼,每輸入一行,按回車(Enter)執行代碼(逐行輸入,逐行執行)。IDLE 每一行以如下提示字符開始: ```python >>> ``` 在 IDLE 中輸入如下代碼開始我們的第一個程序: ```python >>> print('Hello Python!') Hello Python ``` `print()` 是一個函數,將會在終端輸出內容。 **將代碼保存為 .py 文件** 我們開發一個項目,可能有成百上千行代碼,在 IDLE 中寫一行執行一行顯然效率低下,因此我們需要將代碼保存到一個文件中。 像 Word 文檔以 .doc 后綴保存,Python 文件以 .py 后綴保存。如: ``` Hello.py ``` 在終端,進入 Hello.py 文件所在目錄,然后輸入 `python Hello.py` 即可執行輸出: ``` Hello Python ``` **推薦的 Python 開發工具** 為了提高開發效率,有必要使用專業的開發工具。推薦如下: * [JetBrains PyCharm Community](http://www.jetbrains.com/pycharm/) * [NotePad++](https://notepad-plus-plus.org/) * [Visual Studio Code](https://code.visualstudio.com/) 建議安裝 PyCharm。 ***** # 1.2 縮進與注釋 **縮進**是 Python 重要的語法。Python 通過縮進來定義控制與循環結構。一般以 `Tab` 鍵(4個空格)進行縮進。如下: ```python if True: print(1) ``` **注釋**是給人看的,用于對代碼進行解釋說明。Python 有如下三種注釋方法: ```python # 我是單行注釋(我也可以多行注釋,每行都以 # 開頭) ``` ```python ''' 我是多行注釋第一行 我是多行注釋第二行 ... ''' ``` ```python """ 我是多行注釋第一行 我是多行注釋第二行 ... """ ``` ***** # 1.3 變量與表達式 **變量**:Python 中創建變量只需聲明變量名并對其賦值即可。如下: ``` <variable name> = <value> ``` 變量由 `=` 賦值。每聲明一個變量必須為其賦初值——初始化。 ```python # Integer a = 2 print(a) # Output: 2 # Integer b = 9223372036854775807 print(b) # Output: 9223372036854775807 # Floating point pi = 3.14 print(pi) # Output: 3.14 # String c = 'A' print(c) # Output: A # String name = 'John Doe' print(name) # Output: John Doe # Boolean q = True print(q) # Output: True # Empty value or null data type x = None print(x) # Output: None ``` **變量命名規則:** 1. 變量名必須以字母或下劃線開始。 ```python >>> x = 10 >>> x 10 >>> _y = 'Python' >>> _y 'Python' >>> 9x = 18 SyntaxError: invalid syntax ``` 2. 變量名可以是字母、數字和下劃線。 ```python it_0_int = "It's a handsome man." ``` 3. 變量名不能使用 Python 預留關鍵字。 ``` # 以下預留關鍵字不能用作變量名 >>> import keyword >>> print(keyword.kwlist) ['False', 'None', 'True', 'and', 'as', 'assert', 'async','await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise','return', 'try', 'while', 'with', 'yield'] ``` 4. Python 大小寫敏感。 ```python >>> x = 100 >>> y = X * 10 Traceback (most recent call last): File "<pyshell#10>", line 1, in <module> y = X * 10 NameError: name 'X' is not defined ``` 5. 變量命名盡量見名知意。 ```python studentName = 'Joe' # 學生姓名 age = 19 # 年齡 ``` **表達式** ```python >>> 1 + 1 2 ``` 在 Python 中,1 + 1 稱為“表達式”。表達式包含“值”(例如1)和“操作符”(例如+、-、*),并且總是可以求值為單個值。即單個值也可稱為表達式: ```python >>> 2 2 ``` ***** # 1.4 print() 與 input() print() 與 input() 是 Python 自帶的函數。 print() 可將接受的參數在電腦終端上打印出來。 input() 則是接受鍵盤輸入,返回字符串類型。 在 IDLE 中: ```python >>> print('Hello Python.') Hello Python. >>> input('請輸入內容:') 請輸入內容:12 '12' ```
                  <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>

                              哎呀哎呀视频在线观看