擅长:python、mysql、java
<p>类型只定义它们使用的方法。由于可以添加到字符串中的唯一对象是其他字符串或unicode对象,因此不需要常规的<code>__radd__</code>方法。<code>__rmul__</code>允许您复制字符串:</p>
<pre><code>>>> 4 * 'abc'
'abcabcabcabc'
</code></pre>
<p>我不知道为什么需要<code>__rmod__</code>,但它与格式有关。也许它简化了使用单个参数格式化的实现,如<code>"Hello %s" % 'world'</code>。我不确定。与您的断言相反,str对象上没有<code>__rsub__</code>。在</p>
<p>简言之,这些方法只有在它们实际执行某些操作时才被定义。在</p>