title: How to return a list called in a class in python
body: <p>Struggling with this:</p>
  <blockquote>
  <p>Write a function called get_pets_string. get_pets_string should
  have one parameter, an instance of Owner. get_pets_string
  should return a list of that owner's pets according to the
  following format:</p>
  <pre class="lang-none prettyprint-override"><code>David Joyner's pets are: Boggle Joyner, Artemis Joyner
  </code></pre>
  </blockquote>
  <pre class="lang-py prettyprint-override"><code>class Name:
      def __init__(self, first, last):
          self.first = first
          self.last = last
  
  class Pet:
      def __init__(self, name, owner):
          self.name = name
          self.owner = owner
          
  class Owner:
      def __init__(self, name):
          self.name = name
          self.pets = []
  </code></pre>
  <blockquote>
  <p>If your function works correctly, this will originally
  print:</p>
  <pre class="lang-none prettyprint-override"><code>David Joyner's pets are: Boggle Joyner, Artemis Joyner
  Audrey Hepburn's pets are: Pippin Hepburn
  </code></pre>
  </blockquote>
  <pre class="lang-py prettyprint-override"><code>owner_1 = Owner(Name(&quot;David&quot;, &quot;Joyner&quot;))
  owner_2 = Owner(Name(&quot;Audrey&quot;, &quot;Hepburn&quot;))
  
  pet_1 = Pet(Name(&quot;Boggle&quot;, &quot;Joyner&quot;), owner_1)
  pet_2 = Pet(Name(&quot;Artemis&quot;, &quot;Joyner&quot;), owner_1)
  pet_3 = Pet(Name(&quot;Pippin&quot;, &quot;Hepburn&quot;), owner_2)
  
  owner_1.pets.append(pet_1)
  owner_1.pets.append(pet_2)
  owner_2.pets.append(pet_3)
  
  print(get_pets_string(owner_1))
  print(get_pets_string(owner_2))
  </code></pre>
  <p>Here is my code as below:</p>
  <pre class="lang-py prettyprint-override"><code>def get_pets_string(owner):
      for obj in owner.pets:
         return owner.name.first + &quot; &quot; + owner.name.last + &quot;'s pets are: &quot; + obj.name.first + &quot; &quot; + obj.name.last
  
  </code></pre>
  <p>My answer can only print one pet for each owner like this:</p>
  <pre class="lang-py prettyprint-override"><code>David Joyner's pets are: Boggle Joyner
  Audrey Hepburn's pets are: Pippin Hepburn
  </code></pre>