Classes

Definition: A class is a collection of functions grouped together with the data these functions act upon (i.e. a collection of variables). In the context of classes, functions are no longer called function but methods, and variables are called attributes.

Using classes

Accesssing attributes and methods


In [ ]:

Basic data types as classes


In [ ]:

Basic data structures as classes


In [ ]:

Defining classes

Encapsulating data in classes: class attributes


In [ ]:


In [ ]:


In [ ]:


In [ ]:

Encapsulating data in objects: instance attributes


In [ ]:
class student(object):
    def __init__(self, name, major, GPA, UID):
        self.Name = name
        self.major = major
        self.GPA = GPA
        self.UID = UID

In [ ]:
Bob = student('Bob Duran', 'ECON', '3.4', '100003443')

In [ ]:


In [ ]:

Encapsulating functions in classes


In [ ]:
Bob.display()

Inheriting from clases


In [ ]: