Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Change </p> <pre><code>UG.say(person, 'but i like') </code></pre> <p>to</p> <pre><code>ug.say(person, 'but i like') </code></pre> <p><code>UG.say</code> returns the unbound method <code>say</code>. "Unbound" implies that the first argument to <code>say</code> is not automatically filled in for you. The unbound method <code>say</code> takes 3 arguments, and the first one must be an instance of <code>UG</code>. Instead, <code>UG.say(person, 'but i like')</code> sends an instance of <code>Person</code> as the first argument. This explains the error message Python gives to you.</p> <p>In contrast, <code>ug.say</code> returns the bound method <code>say</code>. "Bound" implies that the first argument to say will be <code>ug</code>. The bound method takes 2 arguments, <code>toWhom</code> and <code>something</code>. Thus, <code>ug.say(person, 'but i like')</code> works as expected.</p> <p>The concept of <a href="http://docs.python.org/release/3.0.1/whatsnew/3.0.html#operators-and-special-methods" rel="nofollow">unbound method has been removed from Python3</a>. Instead, <code>UG.say</code> just returns a function which (still) expects 3 arguments. The only difference is that there is no more type checking on the first argument. You'll still end up with an error, however, just a different one:</p> <pre><code>TypeError: say() takes exactly 3 positional arguments (2 given) </code></pre> <p>PS. When beginning to learn Python, I think I'd just try to accept that <code>UG.say</code> returns an unbound method (expecting 3 arguments), and <code>ug.say</code> is the normal proper way to call a method (expecting 2 arguments). Later, to really learn how Python implements this difference of behavior (while maintaining the same qualified name syntax), you'll want to research <a href="http://users.rcn.com/python/download/Descriptor.htm" rel="nofollow">descriptors</a> and the rules of <a href="http://www.cafepy.com/article/python_attributes_and_methods/" rel="nofollow">attribute lookup</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload