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

__init__ can you brief me what is the use of it and also

def init(self, name, sneaky=True, **kwargs): self.name = name self.sneaky = sneaky

here why we use self.name , and self.sneaky what is the use of it can you give me a breif explanation? thank you

1 Answer

Cooper Runstein
Cooper Runstein
11,850 Points

In python classes, init initializes your class, in other words, what you put in your init function will exist as soon as an instance of the class is created. For example:

class Car:
  def __init__(self, color)
    self.color = color

In the above example, I've created a car class, and everytime I create a car object, I can pass it a color to create a car of that color:

red_car = Car('red')

If I were to get the red_cars's property 'color', it would be red.

thank you very much