Realize a simple class Student

http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/001431864715651c99511036d884cf1b399e65ae0d27f7e000

Realize a class is extremely simple .First build a file(this step is not essential in fact,but for convenience) called student.py,then start to write codes.

class Student(object):
    pass

This is a class.Pass means doing nothing,which is convenient to fill codes here later.

Then we add a method init()

class Student(object):
    def __init__(self, name, score):
        self.name = name
        self.score = score

Attention :on the both sides of init,there are two underline.

Method init() is constructor which will be transmitted automatically when instantiate object.first self stands for itself is integral.

results matching ""

    No results matching ""