A719552767 - 20992 - 7 - 2019 - Lecture10 Python OOP
A719552767 - 20992 - 7 - 2019 - Lecture10 Python OOP
INT213
Introduction
• Python has been an object-oriented language
since it existed. Because of this, creating and
using classes and objects are downright easy.
• This chapter helps you become an expert in
using Python's object-oriented programming
support.
Overview of OOP Terminology
• Class:A user-defined prototype for an object that defines a set of
attributes that characterize any object of the class. The attributes are data
members (class variables and instance variables) and methods, accessed
via dot notation.
• Class variable: A variable that is shared by all instances of a class. Class
variables are defined within a class but outside any of the class's methods.
Class variables are not used as frequently as instance variables are.
• Instance variable: A variable that is defined inside a method and belongs
only to the current instance of a class.
• Data member: A class variable or instance variable that holds data
associated with a class and its objects.
• Instance: An individual object of a certain class. An object obj that belongs
to a class Circle, for example, is an instance of the class Circle.
• Instantiation: The creation of an instance of a class.
• Method : A special kind of function that is defined in a class definition.
• Object: A unique instance of a data structure that's defined by its class. An
object comprises both data members (class variables and instance
variables) and methods.
Overview of OOP Terminology
• emp1.displayEmployee()
• emp2.displayEmployee()
• print "Total Employee %d" % Employee.empCount
Example 3
Public and private member of class
Destroying Objects (Garbage
Collection)
• Python deletes unneeded objects (built-in
types or class instances) automatically to free
the memory space.
• The process by which Python periodically
reclaims blocks of memory that no longer are
in use is termed Garbage Collection.
Example 6
Questions
1. Write a class name point for creating 2D points
through constructor.
2.Read and print details of a student using class
programming having attributes name, roll no, reg no,
percentage.
3. Write a class name time, having attributes
hours,minutes, seconds. Define a member function
to add two times.
4. Write a class name threeD, having attributes x, y and
z. Define a member function dist to calculate
Euclidian distance of two threeD points.