Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Ltd
Classes and Objects In Python
●
Shafeeque
●
shafeequemonp@gmail.com
●
www.facebook.com/shafeequemonp pambodan
●
twitter.com/shafeequemonp
●
in.linkedin.com/in/shafeequemonp
●
9809611325
What is a Class?
A class is simply a representation of a type of object.
It is the blueprint/ plan/ template that describe the details of an object.
A class is the blueprint from which the individual objects are created.
Class is composed of three things: a name, attributes, and operations.
i.e. it can be executed from as many different points in Program as required
What is an Object?
● An object represents a particular instance of a class.
● An Object is a collection of data members and associated member
functions also known as methods.
Class declaration:
java:
class class_name {}
public class Dog
{
String breed;
int age;
String color;
void barking()
{
}
void hungry()
{
}
void sleeping()
{
}
}
Class object:
Dog dog=new Dog();
Using object:
objectReference.methodName(); Here, dog.barking();
dog.hungry();
Python classes and objects:
Creating Classes:
Syntax:
class ClassName:
'Optional class documentation string'
class_suite
● The class has a documentation string which can be access
via ClassName.__doc__.
● The class_suite consists of all the component statements, defining class
members, data attributes, and functions.
Creating and accessing instance objects:
● To create instances of a class, you call the class using class
name and pass in whatever arguments its __init__ method
accepts
● Object name=Class_name()
● Eg:class=Class() accessing:objectname.method()
class Employee:
'Common base class for all employees'
def __init__(self, name, salary):
self.name = name
self.salary = salary
def displayEmployee(self):
print "Name : ", self.name, ", Salary: ",
self.salary
"This would create first object of Employee class"
emp1 = Employee("shafeeque", 2000)
"This would create second object of Employee class"
emp2 = Employee("shameer", 5000)
emp1.displayEmployee()
emp2.displayEmployee()
Name : shafeeque ,Salary: 2000
Name : shameer ,Salary: 5000
If this presentation helped you, please visit our page facebook.com/baabtra and
like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com