You should only use *args
if you do not know how many arguments will be passed to function.
In your case, it looks like you need all of president, alive, terms, firstelected
. There is nothing wrong with having a constructor that takes all of those as parameters.
*kwargs
is used for a few reasons. One is if you have default values that should be used, unless the user wants to specify them.
For more info, see this question, this question, and the official documentation.
In response to your comment
I would recommend you do have the datedied
property for each president. If they haven't died yet, then the value should be None
. When you extend only certain instances with functionality, it becomes harder (but not impossible) to reason about the code.
Having said that, if you wanted arbitrary properties for each president that clearly won't be applicable to each instance, then you could use keyword arguments. But adding properties isn't limited to the constructor. I would simply use
setattr() and getattr().
How to set class properties with kwargs
class President(object):
def __init__(self, *args, **kwargs):
for name, value in kwargs.items():
# Make each keyword-argument a property of the class.
setattr(self, name, value)
tVar = President(is_cool=True)
print tVar.is_cool # Returns True