Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Object-Oriented Python Instant Objects Method Arguments

Hara Gopal K
PLUS
Hara Gopal K
Courses Plus Student 10,027 Points

how can we use *args in a class ?

Kenneth explained **kwargs, but how can we use *args in a Class and use them in the methods, any ideas ?

1 Answer

Jeffrey James
Jeffrey James
2,636 Points

*args are positional arguments. Meaning, if you invoke an instance of the class and the signature of the __init__ method has a bunch of args, like __init__(self, name, breed, weight) then you'll probably pattern the init method after setting a bunch of self.name = name, self.breed = breed, etc...

Kwargs is more often relevant in passing data around through mixins or inheritance. Since Python code tends to be written in a more functional and modular paradigm (don't need classes all over the place!), I only tend to see situations like this when you're dealing with Framework code (like customizing a django method or creating a custom class to mirror some existing functionality in another library.

From a purely academic POV, hard to really reason about IMO :)