Can you give me an example shows the meaning of the concept?

Started by
9 comments, last by RLS0812 9 years, 6 months ago

THIS LINK goes into great detail about your question ....

Python class are very strange, as they try to keep some of the C++ syntax


class Teacher():
     
    def __init__(self,name)
        self.name = name

"__init__" is executed every time the object is created

"self" is a reference to the class

"self.name = name" creates a class variable "name" for the class "Teacher" (( why the heck does Python do it this way ?! ))

In Java it's a lot easier to work with objects ...


public class Teacher {
     
     String name;
     
     public Teacher (String n) {
     
          name = n;
     }
}

I cannot remember the books I've read any more than the meals I have eaten; even so, they have made me.

~ Ralph Waldo Emerson

This topic is closed to new replies.

Advertisement