Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 18 Online
OpenStudy (anonymous):

What is it with the __method__? (i understand this question is too big to be exhaustively answrd...) in the lecture and in the recitation they just sort of say it's 'special'. How does it actually help me creating classes? (i'm on pset 5..) Thanks!

OpenStudy (anonymous):

oh, and what's a constructor?

OpenStudy (anonymous):

sorry, did some research..: is the __init__ a constructor? why is it called init? and WHAT DOES IT DO??? (this is indeed a mystery. i've read through the section on classes in the tutorial. none the wiser..)

OpenStudy (anonymous):

thanks, typically silly question. it's just all still very new..

OpenStudy (anonymous):

don't hesitate to ask. did those help?

OpenStudy (anonymous):

yes, but i still don't quite understand what a class IS, what the self argument is, or what the init does.. (oh, it stands for initialize! just got that now..) but i guess working with the concept in pset5 will help more than trying to understand it theoretically.

OpenStudy (anonymous):

a class is another way to encapsulate code like a function does. it allows you to create objects/things with methods and data/attributes that are specific to what you are trying to accomplish. it allows/creates another layer of abstraction - you right a class to serve a purpose then you can write code that uses the class - one thing this does is make the code that uses the class more readable, another is that a class can be instantiated many times creating many things of the same type. One use or way of thinking about it is that you can use classes to make custom data types (like integers or strings) with methods and attributes that are useful to your project. like a point object that has x, y, and z attributes and maybe a method/attribute that returns the distance, angle between itself and another point - a class like this might be very useful in certain types of problems that you are trying to solve and the code that uses it might be easier to write and more readable.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!