4. 2-4 Python 3.5 技術手冊
Welcome to Python 3.5's help utility!
If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/3.5/tutorial/.
Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules. To quit this help utility and
return to the interpreter, just type "quit".
To get a list of available modules, keywords, symbols, or topics, type
"modules", "keywords", "symbols", or "topics". Each module also comes
with a one-line summary of what it does; to list the modules whose name
or summary contain a given string such as "spam", type "modules spam".
help>
這會進入 help()說明頁面,注意提示符號變成了 help>,在上頭這段文字
中有說明頁面的使用方式,像是想結束說明頁面,可以輸入 quit,想哪道有哪
些模組、關鍵字等,可以輸入 modules、keywords 等,例如來看看 Python 中有
哪些關鍵字:
help> keywords
Here is a list of the Python keywords. Enter any keyword to get more help.
False def if raise
None del import return
True elif in try
and else is while
as except lambda with
assert finally nonlocal yield
break for not
class from or
continue global pass
help>
剛才有使用過 print()函式,你會好奇它怎麼使用嗎?在說明頁面中輸入
print 就可以查詢了:
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:
5. 第 2 章 從 REPL 到 IDE 2-5
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.
help>
現在輸入 quit,回到 REPL 中,實際上,在 REPL 中也可以直接輸入
help(print)來查詢函式等說明:
help> quit
You are now leaving help and returning to the Python interpreter.
If you want to ask for help on a particular object directly from the
interpreter, you can type "help(object)". Executing "help('string')"
has the same effect as typing a particular string at the help> prompt.
>>> help(print)
Help on built-in function print in module builtins:
print(...)
print(value, ..., sep=' ', end='n', file=sys.stdout, flush=False)
...略
>>>
如果要離開 REPL 環境,可以執行 quit()函式。實際上,如果只是要執行
個小程式片段,又不想麻煩地進入 REPL,可以在使用 python 指令時加上-c 引
數,之後接上使用""包含的程式片段。例如:
>>> quit()
C:UsersJustin>python -c "print('Hello World')"
Hello World
C:UsersJustin>python -c "help(print)"
Help on built-in function print in module builtins:
print(...)
print(value, ..., sep=' ', end='n', file=sys.stdout, flush=False)
...略
C:UsersJustin>
在 Python 官方網站 www.python.org 首頁,也提供了一個互動環境,臨時要
試個程式小片段,又不想要安裝 Python 或找個裝有 Python 的電腦時,開個瀏
覽器就可以使用囉!