擅长:python、mysql、java
<p>对你的问题</p>
<pre><code>>>>a = Cool({}, 'diana', 1234)
</code></pre>
<p>这是否:</p>
<pre><code>class Cool():
def __init__(self, name, student_num, new_dict):
self._key = name # name is {}
self._value = student_num # student_num is 'diana'
self._new_dict = new_dict # new_dict is 1234
</code></pre>
<p>那么</p>
<pre><code>>>print(a)
</code></pre>
<p>这是否:</p>
<pre><code> def __str__(self):
return str(self._new_dict[self._key])
=> _new_dict is 1234
=> return 1234[self._key]
=> self._key is {}
=> return 1234[{}]
=> TypeError: 'int' object is not subscriptable
</code></pre>
<p><code>something[]</code>是一个下标、一个切片、一个操作,Python不能用数字来实现。你知道吗</p>
<p>我不清楚整个代码应该做什么,但它看起来比它需要的代码多好几倍。我想这其中的一些是任务要求规定的?你知道吗</p>
<p>你在为每个学生开设一个“酷”班吗?还是给很多学生上一节“酷”课?目前看来,这还不确定——如果是每个学生上一节很酷的课,那么把一个名字放进字典里再拿出来,并不会给课堂增加任何东西。如果对很多学生来说这是一门很酷的课,那么<code>get_name</code>就没有意义了,因为会有很多名字,<code>get_student_number</code>需要一种方法来识别哪个学生。你知道吗</p>