From d76e79dfb2bb6ef7657225a899372789d89428f0 Mon Sep 17 00:00:00 2001 From: rakesh Date: Wed, 27 Mar 2019 11:54:14 +0530 Subject: [PATCH] class variable and instance variable --- DataStructure/list_search.py | 2 +- classes/class1.py | 3 +++ classes/class2.py | 5 +++++ classes/classConstructor.py | 27 +++++++++++---------------- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/DataStructure/list_search.py b/DataStructure/list_search.py index 4dc2125..5dc8956 100644 --- a/DataStructure/list_search.py +++ b/DataStructure/list_search.py @@ -1,5 +1,5 @@ # list search using in and ternary operator -# made by : rakesh kumar +# made by : rakesh kumar sharma a=[1,2,3,4,5,6,7,8,9] print( 5 in a and '5 is available in list ' or 'not found') \ No newline at end of file diff --git a/classes/class1.py b/classes/class1.py index 583194b..43fef0a 100644 --- a/classes/class1.py +++ b/classes/class1.py @@ -1,3 +1,6 @@ +# Example of class variable + + class student(): name = "rakesh" website ="binarynote.com" diff --git a/classes/class2.py b/classes/class2.py index eedb656..1fbb126 100644 --- a/classes/class2.py +++ b/classes/class2.py @@ -1,3 +1,8 @@ +# program to show the use of class variable and instance variable +# made by : rakesh kumar +# last compiled on : 27/03/2019 + + class student(): name = "rakesh" website ="binarynote.com" diff --git a/classes/classConstructor.py b/classes/classConstructor.py index e8e2997..5766c69 100644 --- a/classes/classConstructor.py +++ b/classes/classConstructor.py @@ -1,21 +1,16 @@ -class student(): - name="" - website="" - expertise="" - - def __init__(self): - self.name ="swarnima" - self.website = "http://www.swarnima.com" - self.expertise ="Django Specialist" - - def showData(self): - print("Name : ",self.name) - print("website : ", self.website) - print("Expertise :", self.expertise,"\n") +class student: + def __init__(self,name,website,expertise): + self.name = name + self.website = website + self.expertise = expertise + def showdata(self): + return 'Name : {} \nWebsite: {} \nExpertise :{}'.format(self.name,self.website,self.expertise) #object creation # -s1 = student() #calling constructor -s1.showData() +s1 = student('rakehs','https://bianrynote.com','Django Specilist') #calling constructor +print(s1.showdata()) +#calling function using class itself and passing object as its parameter +print(student.showdata(s1)) \ No newline at end of file