❮ Previous Next ❯

Python Class(OOP)


Python Object Oriented Programming


We know that Python is an object oriented programming language. So its main focus is on objects, that means method will be invoked by object then method definition will execute.

In object oriented programming language,object is a memory containing data and method to manipula- te data.

Python Class


As we know a class is a grouping of objects having identical properties, common behavior, and shared some relationships to perform a specified task.

Example: a computer system, a vehicle etc.

But in programming point of view a class is a user-defined data type which fully defines an object. That means without a class, we cant declare an object

An object is also called an instance of a class and the process of creating this object is known as instantiation.

Once a class is declared, we can take any no of objects belonging to that class.

Python classes contain all the standard features of Object Oriented Programming. Lets see an example for better understanding:


# Class Example


class Student:

     def show(self,fName,lName):
        self.fName=fName
        self.lName=lName
     def display(self):
        print(self.fName,"",self.lName)


s=Student()
s.show("Trilochan","Tarai")
s.display()

Output


Trilochan Tarai

Here Student is a class containing get() and show(). We have defined get() and show() function. It is noted that inside a class when we are defining a function, that function must take self argument. The keyword self represent current instance(object).

We have taken s as object of type Student, then get() and show() have invoked by s. It is pointing that when get() and show() invoking by s, then get() and show() definition executing, such concept is also known as message passing.

❮ Previous Next ❯

Follow Us




  Tutorials

Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Bhubaneswar-751013
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved