擅长:python、mysql、java
<p>通过创建<code>Person</code>类,可以简化一些代码。你知道吗</p>
<pre><code>class Person:
def __init__(self, first, last, rate, hours):
self.first = first
self.last = last
self.rate = rate
self.hours = hours
def matches_name(self, name):
return name.lower() == self.first.lower() or name.lower() == self.last.lower()
def __str__(self):
return '{} {} {}'.format(self.first, self.last, self.rate*self.hours)
</code></pre>
<p>这将简化您的代码一点。如果你想知道某人是否有特定的名字,你可以这样称呼:</p>
<pre><code>a_person.matches_name(random_first_name)
</code></pre>
<p>如果你想打印出这个人和他们的工资总额,你只需要</p>
<pre><code>print(a_person)
</code></pre>