Hello I am learning python and I have this working code but in most of Object Oriented examples of python, I see people use extra stuff and I am not sure why do we need those.
I will try to explain my question with comments in the code.
class Node:
data = none
next = none
# Question1: Why do we have these variables outside of
# __init__ fucntion? what are their applications?
def __init__(self, val):
self.data = val
self.next = None
def display(self):
next = self
while next.next:
print next.data, "->",
next = next.next
print next.data
# Question2: Do we need getter setter functions to access
# the attributes above? I was able to remove a node with
# simple function and it worked well
def denode(node):
node.next = node.next.next
# Question 3: for many implementation samples of a linked
# list or something that uses Node, I see that example
# uses another class, but in the example below I was able
# to create a linked list without any trouble. why do we
# need a separate class to create a linked list?
#ex
node1 = Node(123)
node2 = Node(134)
node3 = Node(139)
node4 = Node(148)
node1.next=node2
node2.next= node3
node1.display()
denode(node1)
node1.display()