2014-10-28 61 views
6
>>> print(len.__doc__) 
len(module, object) 

Return the number of items of a sequence or mapping. 
>>> len(os, 1) 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
TypeError: len() takes exactly one argument (2 given) 

注意兩個參數在文檔字符串的第一行。什麼是len的文檔字符串中的「module」?

你什麼時候將兩個參數傳遞給len?文檔字符串是否不正確?我正在使用Python 3.4.0。

+2

對我來說,'打印(LEN .__ DOC __)'打印** LEN(對象)序列的項目 歸還號碼或收集。** – falsetru 2014-10-28 13:28:44

+0

@falsetru這很奇怪。你使用哪個版本的Python? – rightfold 2014-10-28 13:29:04

+0

我使用Python 3.4.2 – falsetru 2014-10-28 13:29:20

回答

9

這是一個在2014-04-18 here上提交的錯誤。它已在3.4.1中得到修復。

引用韋德蘭Čačić,錯誤報告原作者:

From recently, help(len) gives the wrong signature of len. 

Help on built-in function len in module builtins: 

len(...) 
    len(module, object) 
     ^^^^^^^^ 
    Return the number of items of a sequence or mapping. 
+1

[Python 3.5.0 alpha 1](https://github.com/python/cpython/blob/master/Python/bltinmodule.c#L1836)也包含兩個參數在'len()'的文檔字符串中,但是文檔字符串略有不同,模塊對象根本沒有被使用。 – 2014-10-28 13:39:53