+ 1

How to print out age?

Says list object has no attribute ’age’? How do i give a list an attribute? https://code.sololearn.com/clEnrdn627W0/?ref=app

25th Feb 2022, 5:24 PM
Lenoname
5 Respostas
+ 1
Right, but each of thos 3 attributes is stored in the Instantiated person class. The class IS THE CONTAINER. No need for lists within lists. You can just append a Person to the list and then use index notation once to access induvidual people's attributes.
25th Feb 2022, 5:54 PM
Slick
Slick - avatar
+ 1
Take away the square brackets around 'P' on line 28. You add a list to the list. So when accessing personList you just see another list. And lists dont have an 'age' attribute
25th Feb 2022, 5:33 PM
Slick
Slick - avatar
+ 1
Why should it be 2 dimensional, explain? It's not like you're seperating attributes as that's done by keeping them in the classes. Either way, you're trying to access the Person class outside the list and it wont work. It would work if you wrote: print(personList[0][0].name) But that just shows there's no point in making the list 2 dimensional.
25th Feb 2022, 5:44 PM
Slick
Slick - avatar
0
Slick the list should be two dimensional, if i remove the bracket around P and print the list, it would not look like a two dimensional list, (but it would act like a 2dimensional since i can print(personList[0].name))
25th Feb 2022, 5:40 PM
Lenoname
0
Slick because there will be multiple persons information stored in the personList,every 3 values represent a person and his information(name,age,gender)
25th Feb 2022, 5:52 PM
Lenoname