Implement a simple Student class

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

Implementing a class is very simple. First, create a file (this step is not necessary, but for convenience), called student.py and then start writing code.

class Student(object):
    pass

This is a class. Pass means do nothing. For convenience, fill in the code here later.

Then we add a method. init()

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

Note: There are two underscores on both sides of init.

The init() method is the constructor, which is automatically called when the object is instantiated. The first self is required and represents itself.

results matching ""

    No results matching ""