PYTHON NOTES JEGAN K K
ABSTRACT CLASS
Abstract classes can be created in which cases like a function must be implemented in the
derived or sub-classes.
Syntax:
from abc import ABC, abstractmethod
class Animal(ABC):
@abstractmethod
def move():
pass
class Dog(Animal):
def move():
pass
In the above example the class Dog must have a definition for the method move()
which is an abstract method.
Without definition, it wouldn’t instantiate the references created for the Dog class.
I had chosen move because move() is a mandatory function for any animal.
The definition has no constraint, it has to be defined in the sub-class with same
method name
LINKED LIST
Linked List is a data structure in which there is a chain of nodes present with 2 fields
each. First field is the data and the second is the reference (i.e, next).
Reference field holds the reference for the next node, therefore connecting it like a series
of elements.
Linked List is of 3 types in general terms,
1. Singly Linked List
2. Doubly Linked List
3. Circular Linked List
where singly circular linked list, doubly circular linked list can be created by connecting
nodes in a circular form.
Doubly linked list has 3 fields, which is previous node reference, data, next node
reference.
Difference between singly and doubly linked list is that singly linked list can be traversed
only forward whereas doubly linked list can be traversed in both forward and backward
ways.
ABSTRACT CLASS
Abstract classes can be created in which cases like a function must be implemented in the
derived or sub-classes.
Syntax:
from abc import ABC, abstractmethod
class Animal(ABC):
@abstractmethod
def move():
pass
class Dog(Animal):
def move():
pass
In the above example the class Dog must have a definition for the method move()
which is an abstract method.
Without definition, it wouldn’t instantiate the references created for the Dog class.
I had chosen move because move() is a mandatory function for any animal.
The definition has no constraint, it has to be defined in the sub-class with same
method name
LINKED LIST
Linked List is a data structure in which there is a chain of nodes present with 2 fields
each. First field is the data and the second is the reference (i.e, next).
Reference field holds the reference for the next node, therefore connecting it like a series
of elements.
Linked List is of 3 types in general terms,
1. Singly Linked List
2. Doubly Linked List
3. Circular Linked List
where singly circular linked list, doubly circular linked list can be created by connecting
nodes in a circular form.
Doubly linked list has 3 fields, which is previous node reference, data, next node
reference.
Difference between singly and doubly linked list is that singly linked list can be traversed
only forward whereas doubly linked list can be traversed in both forward and backward
ways.