In [1]:
class Node(object):
    
    ## Constructor: see [1] 
    ## specifies the components of an object 
    ## (the stuff to put in a box)
    
    def __init__(self, d, n = None):
        ## single underscore v double underscore in Python
        ## double = only used in this class 
        ## (totally private variable or function)
        self.data = d
        self.next_node = n
        
    def get_next(self):
        ## great stackoverflow explaining use of "self" [2]
        return self.next_node
    
    def set_next(self, n):
        self.next_node = n
        
    def get_data(self):
        return self.data
    
    def set_data(self, d):
        self.data = d
    
    def __str__(self):
        print self.data
        print self.next_node
In [6]:
node1 = Node(1)
node2 = Node(2)
node1.next_node = node2
In [7]:
node1.data
Out[7]:
1
In [9]:
node1.next_node.data
Out[9]:
2
In [10]:
class NodePrivate(object):
    
    ## Constructor: see [1] 
    ## specifies the components of an object 
    ## (the stuff to put in a box)
    
    def __init__(self, d, n = None):
        ## single underscore v double underscore in Python
        ## double = only used in this class 
        ## (totally private variable or function)
        self.__data = d
        self.__next_node = n
        
    def get_next(self):
        ## great stackoverflow explaining use of "self" [2]
        return self.__next_node
    
    def set_next(self, n):
        self.__next_node = n
        
    def get_data(self):
        return self.__data
    
    def set_data(self, d):
        self.__data = d
    
    def __str__(self):
        print self.__data
        print self.__next_node
In [11]:
node3 = NodePrivate(2)
In [14]:
node3.get_data()
Out[14]:
2
In [15]:
class NodeProperties(object):
    
    def __init__(self, d, n = None):

        self.__data = d
        self.__next_node = n
    
    @property
    def data(self):
        return self.__data
        
    @property
    def next_node(self):
         return self.__next_node
        
    @next_node.setter
    def next_node(self, n):
        self.__next_node = n
        
    @data.setter
    def data(self, d):
        self.__data = d
    
    def __str__(self):
        print self.__data
        print self.__next_node
In [27]:
node4 = NodeProperties(3)
node5 = NodeProperties(4)
In [20]:
node4.data
Out[20]:
3
In [28]:
node3.next_node = node5
In [30]:
node3.next_node.data
Out[30]:
4
In [31]:
class NodePublic(object):
    
    def __init__(self, d, n = None):
        self.data = d
        self.next_node = n
        
    def __str__(self):
        print self.data
        print self.next_node
In [32]:
node6 = NodePublic(3)
node7 = NodePublic(4)
In [34]:
node6.data = 5
In [36]:
node6.data
Out[36]:
5
In [ ]: