prev | Creating Python classes and invoking functions #define a class named Myclass. Variables begin with __ is strictly private can't be accessed outside the class class Myclass: i=10 #public variable _j=20 __k=30 # private def f1(self): print 'Linux' print "=>",self.i def f2(self,fname): print 'inside f2' fp=open('classes.py','r') # just prints this file fp.readline() #print line by line to output screen. #create an instance called x x=Myclass() x.f1() # call the funcation with out arguments print "i=",x.i print "_j=",x._j #print "__k=",x.__k #will give error if you uncomment this line x.f2('classes.py') #Calling function with an argument |
next |