Class

Since we are going to save student information, the class is going to be called Student. A class is defined using the class keyword as follows:

class Student(object):

Thus, a class called Student has been defined. Whenever a new object is created, the method __init__() (the underscore indicate that the init method is a magic method, that is it is a function that is called by Python when an object is created) is called internally by Python. This method is defined within the class:

class Student(object):     """A Python class to store student information"""     def __init__(self, name, address, age):         self.name = name         self.address = address         self.age = age

In this example, the arguments to the __init__ method include name, age and address ...

Get Python Programming with Raspberry Pi now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.