title: Creating objects inside a Class in python
body: <p>So i have this class in python</p>
  
  <pre><code>class room (object):
  
      def __init__(self,number):
          self.room_number=number
  
      def get_room_num(self):
          return self.room_number
  </code></pre>
  
  <p>And i have another class called House, basically when i create the house object, i also need to create room objects for the house, and the number of rooms will be chosen by the user.</p>
  
  <p>I have difficulty with creating dynamic objects (since it is specified by the user, we would have 1 room or 10 room), i can't give each room object a name since i won't know how many there are before hand. </p>
  
  <p>So i tried like this </p>
  
  <pre><code>class House (object):
  
      def __init__(self,num_of_rooms):
          self.room_holder=[]
          for i in range(num_of_rooms):
              self.room_holder.append(room(i))
  
      def __iter__(self):
          return iter(self.room_holder)
  </code></pre>
  
  <p>is there a better way to do it?, if so please help</p>
  
  <p>the <strong>iter</strong> function is there so i can iterate over it, example</p>
  
  <pre><code>mansion=House(10)
  
  for i in mansion:
      print i.get_room_num()
  </code></pre>