首頁>技術>

近日,微軟上線了一套 Python 教程《Develop with Python on Windows》

介紹完Python語言後,第一節課就是建立一個應用,趕緊來試試你是否能學會

第一課 練習 - 建立第一個應用

必須使用沙盒,才能完成此模組。 使用沙盒,便有權訪問 Azure 資源。 Azure 訂閱將不會收費。 沙盒僅限用於在 Microsoft Learn 上完成培訓。 禁止將沙盒用於任何其他目的,否則可能會導致永遠無法使用沙盒。

Python 入門的一種好方法是學習如何執行輸入和輸出。 Python 中有 60 多個內建到語言的函式,print 函式就是其中之一,用於將文字輸出到螢幕。 下面的語句在螢幕上 顯示“Hello World!”:

Python

print('Hello World!')  

傳遞到 print 的引數是字串,這是 Python 中用於儲存和管理文字的基礎資料型別之一。 預設情況下,print 在行末尾輸出一個換行符,以便後續輸出(例如對 print 的其他呼叫)會在下一行開始。

請使用第一個 Python 語句Python 支援互動式控制檯體驗,你可以鍵入命令並立即檢視結果。 這有時稱為“讀取–求值–輸出-迴圈”或 REPL。 我們可以在右邊的 Cloud Shell 中試用。

鍵入 python 已在互動模式中啟用 Python 直譯器。

Bash

python  

提示

應當會看到與以下內容類似的輸出:

輸出

Python 3.5.2 (default, Nov 12 2018, 13:43:14) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. 

是直譯器在等待你鍵入 Python 命令。 將以下語句鍵入到直譯器中。

Python

print('Hello World!')  

它應該將文字直接回復給你,然後再發出一個等待下一條命令的提示。

輸出

Hello World! 

獲取幫助REPL 有一個可用於查詢關鍵字和函式的內建幫助函式。 此函式的通用語法是:

Python

help([object])  

其中 [object] 是你想獲取有關其幫助的特定函式或關鍵字。 我們來嘗試一些示例。

鍵入以下命令以獲取有關 print 函式的幫助。

Python

help(print)  

這將顯示以下輸出:

輸出

Help on built-in function print in module builtins:print(...)    print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)      Prints the values to a stream, or to sys.stdout by default.   Optional keyword arguments:   file:  a file-like object (stream);defaults to the current sys.stdout.   sep:   string inserted between values, default a space.   end:  string appended after the last value, default a newline.   flush: whether to forcibly flush the stream. 

鍵入 q 退出幫助螢幕並返回到直譯器提示。

互動式幫助控制檯如果不將引數傳遞到幫助函式,則會啟動互動式幫助工具。

鍵入 help() 以進入互動式幫助控制檯。 這將列出一些關於如何使用幫助系統的基本說明。

在這裡,只需鍵入你感興趣的元素。 鍵入 string 獲取關於 string 資料型別的幫助。 它將顯示與以下內容類似的內容:

輸出

Help on module string:NAME string - A collection of string constants. MODULE REFERENCE     https://docs.python.org/3.5/library/string.html      The following documentation is automatically generated from the Python     source files.It may be incomplete, incorrect or include features that are considered implementation detail and may vary between Python implementations. When in doubt, consult the module reference at the location listed above. 

如果有多個頁面的輸出,可以按 Enter 逐行顯示,或者按空格鍵逐頁顯示。

到達幫助螢幕末尾後,鍵入 q 退出頁面。 這將返回到互動式幫助提示。

可在此處隨意瀏覽更多內容 - 例如,可透過鍵入 keywords 獲取 Python 關鍵字列表。

完成後,鍵入 quit 返回到互動式提示。

17
  • BSA-TRITC(10mg/ml) TRITC-BSA 牛血清白蛋白改性標記羅丹明
  • 12種最常見的JavaScript數字方法