I have made a simple, test program to experiment using classes. It creates a "person" class, which takes the arguments of name and age. I am now trying to create an interactive program that allows the user to manage a list of people, like a register or address book. They can create a new person, as shown in the function below.
def createnew():
newname = input("What is their name?")
newage = input("How old are they?")
newperson = Person(newname, newage)
Of course the problem with the above is it assigns newname literally rather than the string value of "newname". So I tried
newperson.lower() = Person(newname, newage)
str(newperson) = Person(newname, newage)
newperson[0:] = Person(newname, newage)
but they all return the error, can't assign to function call. My question is how do I access the value of the variable newname and assign it to the Person, or any other class.
Note: I am a n00b/newb, meaning I have not come from another language, and am following a book. Please explain any answers given if they are not ridiculously obvious.
Many Thanks.
To make it slightly clearer, I am trying to make the user-inputted value for the new person's name the object name ( in my example it is newperson )
Update:
Thanks for all the answers, I gather it's not a great idea to allow the user to set variable names so I re-jigged my code. I made a dictionary which after the user has created a new person, writes the data given by the class str function to the key of the given name. While this means I can't then access the object later on, because newperson will have been overwritten, it allows me to build a list of people with a set of data which is what I wanted to do in the first place, I just mistakingly thought it would be easier to set the object name. Thanks again.