-1

I am trying to learn python 3.x. Below is a simple program I wrote-

class Movie:
    def __init__(self, movieName,movieTitle,movieHero):
        self.name   =movieName
        self.title  =movieTitle
        self.hero   =movieHero

    def movieDetails(self):
        print (self.name,self.title,self.hero)


detailsOfMovie= []

while True:
    a,b,c = [x for x in input("Enter movie, title, hero").split(",")]
    m=Movie(a,b,c)

    detailsOfMovie.append(m)


    option = input ("Do you want to print another movie [Yes or No]:")
    if option.lower() == 'no':
        break


for x in detailsOfMovie:
    print(x)

BUT it returns the below result-

Enter movie, title, hero df,df,df
Do you want to print another movie [Yes or No]:no
<__main__.Movie object at 0x00000221EF45FC88>

Process finished with exit code 0

Question Is: Why did it not print the items in the list detailsOfMovie?

khelwood
  • 55,782
  • 14
  • 81
  • 108
SQA
  • 9
  • 3
  • 1
    It did. The item in the list is an instance of `Movie`, and that's what that looks like when you print it. – khelwood Sep 26 '20 at 08:58
  • Does this answer your question? [How to print instances of a class using print()?](https://stackoverflow.com/questions/1535327/how-to-print-instances-of-a-class-using-print) – khelwood Sep 26 '20 at 08:59

1 Answers1

2

m is an object Movie. Instead of print(x), try:

for x in detailsOfMovie:
    x.movieDetails()
smekkley
  • 62
  • 2