Pythonclass

140 views
116 views

Published on

Pythonclass

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
140
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

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

×