An Example of class, Class as Abstract Data Type, Date Class
By:
P. Gayathri
I M.SC CS
Department of Computer Science
Nadar Saraswathi College of arts and science
Python programming
Class:
A class is considered as a blueprint of objects. We can think of the class as a sketch (prototype) of a
house. It contains all the details about the floors, doors, windows, etc. Based on these descriptions we build
the house. House is the object.
Object:
An object is simply a collection of data (variables) and methods (functions). Similarly, a class is a
blueprint for that object.
Define Python Class
We use the class keyword to create a class in Python. For example,
class classname :
# class definition
Example:
Class bike:
name=“”
gear=0
Bike is the name of the class and name and gear is the
variables for the class.
Example
class Employee:
id = 10
name = "Devansh"
def display (self):
print(self.id , self.name)
Here, the self is used as a reference variable, which refers to the current class object.
It is always the first argument in the function definition. However, using self is optional in the function
call.
The self-parameter
The self-parameter refers to the current instance of the class and accesses the class variables.
We can use anything instead of self, but it must be the first parameter of any function which belongs to
the class.
Class as Abstract Data Type:
 Abstract Data type (ADT) is a type (or class) for objects whose behavior is
defined by a set of values and a set of operations.
 The definition of ADT only mentions what operations are to be performed but
not how these operations will be implemented.
 It does not specify how data will be organized in memory and what algorithms
will be used for implementing the operations.
We can use the following syntax to create an abstract class in Python:
from abc import ABC
class <Abstract_Class_Name>(ABC):
# body of the class
Data Class
Data class module is introduced in Python 3.7 as a utility tool to make
structured classes specially for storing data. These classes hold certain
properties and functions to deal specifically with the data and its
representation.
The Data Classes are implemented by using with classes. Attributes are
declared using Type Hints in Python which is essentially, specifying
data type for variables in python.
Equality of Data Classes
Since the classes store data, checking two objects if
they have the same data is a very common task that’s
needed with data classes. This is accomplished by using
the == operator.
Below is the code for an equivalent class for storing an
article without a data class decorator.
THANK YOU

python.pptx

  • 1.
    An Example ofclass, Class as Abstract Data Type, Date Class By: P. Gayathri I M.SC CS Department of Computer Science Nadar Saraswathi College of arts and science Python programming
  • 2.
    Class: A class isconsidered as a blueprint of objects. We can think of the class as a sketch (prototype) of a house. It contains all the details about the floors, doors, windows, etc. Based on these descriptions we build the house. House is the object. Object: An object is simply a collection of data (variables) and methods (functions). Similarly, a class is a blueprint for that object.
  • 3.
    Define Python Class Weuse the class keyword to create a class in Python. For example, class classname : # class definition
  • 4.
    Example: Class bike: name=“” gear=0 Bike isthe name of the class and name and gear is the variables for the class.
  • 5.
    Example class Employee: id =10 name = "Devansh" def display (self): print(self.id , self.name) Here, the self is used as a reference variable, which refers to the current class object. It is always the first argument in the function definition. However, using self is optional in the function call. The self-parameter The self-parameter refers to the current instance of the class and accesses the class variables. We can use anything instead of self, but it must be the first parameter of any function which belongs to the class.
  • 6.
    Class as AbstractData Type:  Abstract Data type (ADT) is a type (or class) for objects whose behavior is defined by a set of values and a set of operations.  The definition of ADT only mentions what operations are to be performed but not how these operations will be implemented.  It does not specify how data will be organized in memory and what algorithms will be used for implementing the operations.
  • 7.
    We can usethe following syntax to create an abstract class in Python: from abc import ABC class <Abstract_Class_Name>(ABC): # body of the class
  • 8.
    Data Class Data classmodule is introduced in Python 3.7 as a utility tool to make structured classes specially for storing data. These classes hold certain properties and functions to deal specifically with the data and its representation. The Data Classes are implemented by using with classes. Attributes are declared using Type Hints in Python which is essentially, specifying data type for variables in python.
  • 9.
    Equality of DataClasses Since the classes store data, checking two objects if they have the same data is a very common task that’s needed with data classes. This is accomplished by using the == operator. Below is the code for an equivalent class for storing an article without a data class decorator.
  • 10.