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 ?
m is an object Movie. Instead of print(x), try:
for x in detailsOfMovie:
x.movieDetails()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.