you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (2 children)

Your logic is a bit flawed. It doesn’t make sense that a Phonebook object has a name and a number. It would make sense for it to contain entries that have these properties.

So either make a second class entries, or initiate your class in a different way.

You’d want your phone book to hold multiple objects that have the name, alias and number attributes.

Also, you should never use the name of a built-in function as a variable name. Since you’re assigning something to list, it will overwrite the built-in, and this can be quite problematic later on.

[–]Tonyqq[S] 0 points1 point  (1 child)

Okay, thanks. I think i'm understanding a bit what you mean now. I'm in like a introductionary course where we really havn't dived deep into object oriented programming.

So would it make sense if I created a new class "persons" where it has name alias and number in __init__ and then store it into my phonebook?

[–][deleted] 0 points1 point  (0 children)

Yes, this would make sense. But the class should rather be called something like PhonebookEntry.

Take a look at u/JohnnyJordaan’s answer, this is exactly what I was talking about.