CodesJava

Easy learning with example program codes

Python Object Class


Python Object Class:

Like Java and C++, Python is also based on OOPs Concept, i.e, Python is an object-oriented programming language which uses classes and objects for computations.

Python Class:

A collection of Objects is termed as Class in OOPs concept. Every class has its own unique and distinguishable attributes and methods.

Syntax:

class ClassName:

<statement-1> 

    . 

    . 

    . 

    <statement-N> 

 

Python Object:

Anything that has state and behavior can be termed as an Object, be it physical or logical. An Object is an entity mentioned in OOPs concept and is frequently found in Python codes.

Creating an object in Python is similar as calling a function. The objects attributes can then be accessed by using the object name prefix.

Example:

class Employees(): 
   def __init__(self, Name, Salary): 
       self.Name = Name
       self.Salary = Salary
 
   def details(self): 
       print "Employee Name : ", self.Name
       print "Employee Salary: ", self.Salary
       print "\n"
 
first = Employees("Khush", 10000) 
second = Employees("Raam", 20000)
third = Employees("Lav", 10000)
fourth = Employees("Sita", 30000)
fifth = Employees("Lucky", 50000)
 
first.details() 
second.details() 
third.details()
fourth.details()
fifth.details()

Output:

Sign Up/ Sign In
Ask a Question


Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki