-1
class Objects:
   def __init__(self, name):
     self.name = name

   def sayHi(self):
      print("Hi! My name is " + self.name)

myObjects = []
object1 = Objects("David")

How do i put object1 into the myObjects? And if i did put object1 in, how do I call it's sayHi func?

codeBit
  • 84
  • 2
  • 10
  • `myObjects.append(object1)` and `myObjects[0].sayHi()`. ..these are very basic python questions. i suggest you take a course or read a book first. – hiro protagonist Oct 19 '20 at 12:48
  • duplicate was second google result for your question's title with "python" after it – Sayse Oct 19 '20 at 12:51

1 Answers1

3

you can simply append the object to the list:

myObjects.append(object1)

Later you can access these by iterating over the list as follows:

for obj in myObjects:
    obj.sayHi()
Faizan Naseer
  • 589
  • 3
  • 12