Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Pythonclass

175 views

Published on

Pythonclass

Published in: Education
  • Be the first to comment

  • Be the first to like this

Pythonclass

  1. 1. 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
  2. 2. Classes and Objects In Python ● Shafeeque ● shafeequemonp@gmail.com ● www.facebook.com/shafeequemonp pambodan ● twitter.com/shafeequemonp ● in.linkedin.com/in/shafeequemonp ● 9809611325
  3. 3. 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.
  4. 4. Class declaration: Syntax: Cpp: class class_name {}; class class_name { access_specifier_1://public/private/protected member1;//member variables//member functions access_specifier_2: member2; ... } object_names; Class definition: Eg:class CRectangle { int x, y; public: void set_values (int,int); int area (void); } Class object: class_name object_name Eg:CRectangle rect; rect.x;or rect.set_values();
  5. 5. 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();
  6. 6. 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()
  7. 7. 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
  8. 8. 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
  9. 9. 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

×