Size: 1152
Comment:
|
Size: 1259
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 11: | Line 11: |
= 问:问题的翻译? = ''Q: The f(*m) trick is cool. Does the same syntax work with method calls, like x.f(*y)?'' |
= 问:f(*m)这个技巧确实不错。不知道这个语法是否可以用在方法调用上, 比如 x.f(*y)? = ''Q: f(*m)这个技巧确实不错。不知道这个语法是否可以用在方法调用上, 比如 x.f(*y)?'' |
返回::[wiki:self/PyIAQ Python 罕见问题集]
::-- ["huangyi"] [DateTime(2006-04-22T16:26:39Z)] TableOfContents
::-- ZoomQuiet [DateTime(2005-09-06T04:10:30Z)] TableOfContents
1. 问:f(*m)这个技巧确实不错。不知道这个语法是否可以用在方法调用上, 比如 x.f(*y)?
Q: f(*m)这个技巧确实不错。不知道这个语法是否可以用在方法调用上, 比如 x.f(*y)?
This question reveals a common misconception. There is no syntax for method calls! There is a syntax for calling a function, and there is a syntax for extracting a field from an object, and there are bound methods. Together these three features conspire to make it look like x.f(y) is a single piece of syntax, when actually it is equivalent to (x.f)(y), which is equivalent to (getattr(x, 'f'))(y). I can see you don't believe me. Look: