Adding methods to a class

Let's add some methods to our Student class that would help retrieve a student's information:

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

In this example, we have added three methods namely return_name(), return_age() and return_address() that returns the attributes name, age and address respectively. These methods of a class are called callable attributes. Let's review a quick ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.