大家知道Python一共有多少個內置函數嗎?
答案是:一直在變,所以當下有多少不確定!
那我們可以手動來查看一下,打開 IDLE,輸入
dir(__builtins__)
即可:
>>> dir_list = dir(__builtins__)
>>> len(dir_list)
153
看來目前有 153 個 Python 的內置函數!
如果大家使用 print,就可以看到具體哪 153 個。
好了,接下來我們講解下這些內置函數的用法!
你以爲我瘋了嗎?講 153 個用法?
正所謂授人以魚不如授人以漁!我要分享的是如何簡單快捷地查詢用法!我相信即使大家把每個用法看一遍也是記不住的,不如瞭解下有哪些,然後未來需要用的時候,隨手一查如何使用即可!
案例
>>> help(input)
Help on built-in function input in module builtins:
input(prompt=None, /)
Read a string from standard input. The trailing newline is stripped.
The prompt string, if given, is printed to standard output without a
trailing newline before reading input.
If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.
On *nix systems, readline is used if available.
我們需要查詢哪個內置函數,只要用 help( ) 即可,是不是很簡單?是不是很快捷?