【发布时间】:2015-04-26 13:12:41
【问题描述】:
所以,我才刚刚开始学习 Python(使用 Codecademy),我有点困惑。
为什么有些方法带参数,而有些方法使用点符号?
len() 接受一个参数,但不能使用点符号:
>>> len("Help")
4
>>>"help".len()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'len'
同样:
>>>"help".upper()
'HELP'
>>>upper("help")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'upper' is not defined
【问题讨论】:
-
Guido 在这里解释:effbot.org/pyfaq/…