### 3. 不太重要的內建函數
有幾個內建的函數在現代Python編程中已經沒有必要再學習、知道和使用了。這里保留它們是為了保持為老版本Python編寫的程序的向后兼容。
Python程序員、培訓人員、學生以及書籍編寫人員應該自由跳過這些函數而不用擔心遺漏重要的內容。
apply(*function*, *args*[, *keywords*])
The *function* argument must be a callable object (a user-defined or built-in function or method, or a class object) and the *args* argument must be a sequence.The *function* is called with *args* as the argument list;the number of arguments is the length of the tuple.If the optional *keywords* argument is present, it must be a dictionary whose keys are strings.It specifies keyword arguments to be added to the end of the argument list.Calling [apply()](# "apply") is different from just calling function(args), since in that case there is always exactly one argument.The use of [apply()](# "apply") is equivalent to function(*args,**keywords).
自2.3版后廢棄:使用function(*args,**keywords)來代替apply(function,args,keywords)(參見[*Unpacking Argument Lists*](#))。
buffer(*object*[, *offset*[, *size*]])
*object*參數必須是一個支持緩沖區調用接口的對象(例如字符串、數組和緩沖區)。將創建一個新的引用*object*參數的緩沖區對象。緩沖區對象將是一個從*object*的起點開始的切片(或者從指定的*offset*)。切片將擴展到*object*對象的末尾(或者通過*size*參數指定的長度)。
coerce(*x*, *y*)
Return a tuple consisting of the two numeric arguments converted to a common type, using the same rules as used by arithmetic operations.If coercion is not possible, raise [TypeError](# "exceptions.TypeError").
intern(*string*)
Enter *string* in the table of “interned” strings and return the interned string – which is *string* itself or a copy.Interning strings is useful to gain a little performance on dictionary lookup – if the keys in a dictionary are interned, and the lookup key is interned, the key comparisons (after hashing) can be done by a pointer compare instead of a string compare.Normally, the names used in Python programs are automatically interned, and the dictionaries used to hold module, class or instance attributes have interned keys.
2.3版中的變化:Interned strings are not immortal (like they used to be in Python 2.2 and before);you must keep a reference to the return value of [intern()](# "intern") around to benefit from it.
腳注
| [[1]](#) | 它極少被使用,所以不應該成為語句。 |
|-----|-----|
| [[2]](#) | 當前在沒有setvbuf()的系統上指明緩沖大小是沒有效果的。該接口指明緩沖大小不是通過調用setvbuf()函數來實現的,因為在執行任意的I/O操作后再調用該函數可能會導致內存轉儲,同時也沒有一個可靠的方法來判斷這種情況。 |
|-----|-----|
| [3] | In the current implementation, local variable bindings cannot normally be affected this way, but variables retrieved from other scopes (such as modules) can be.This may change. |
|-----|-----|
- Python 2 教程
- 1. 吊吊你的胃口
- 2. Python 解釋器
- 3. Python簡介
- 4. 控制流
- 5. 數據結構
- 6. 模塊
- 7. 輸入和輸出
- 8. 錯誤和異常
- 9. 類
- 10. 標準庫概覽
- 11. 標準庫概覽 — 第II部分
- 12.現在怎么辦?
- 13. 交互式輸入的編輯和歷史記錄
- 14. 浮點數運算:問題和局限
- Python 2 標準庫
- 1. 引言
- 2. 內建函數
- 3. 不太重要的內建函數
- 4. 內建的常量
- 5. 內建的類型
- 6. 內建的異常
- 7. String Services
- 8. Data Types
- 9. Numeric and Mathematical Modules
- 10. File and Directory Access
- 11. Data Persistence
- 13. File Formats
- 14. Cryptographic Services
- 15. Generic Operating System Services
- 16. Optional Operating System Services
- 17. Interprocess Communication and Networking
- 18. Internet Data Handling
- 20. Internet Protocols and Support
- 26. Debugging and Profiling
- 28. Python Runtime Services
- Python 2 語言參考
- 1. 簡介
- 2. 詞法分析
- 3. 數據模型
- 4. 執行模型
- 5. 表達式
- 6. 簡單語句
- 7. 復合語句
- 8. 頂層的組件
- 9. 完整的語法規范
- Python 3 教程
- 1. 引言
- 2. Python 解釋器
- 3. Python簡介
- 4. 控制流
- 5. 數據結構
- 6. 模塊
- 7. 輸入和輸出
- 8. 錯誤和異常
- 9. 類
- 10. 標準庫概覽
- 11. 標準庫概覽 — 第II部分
- 12.現在怎么辦?
- 13. 交互式輸入的編輯和歷史記錄
- 14. 浮點數運算:問題和局限