''' This code use python class syntax - save this class named "MyClass.py" ''' class MyClass(): # Class constructor def __init__(self,data): self.data=data def showSring(self): print self.data def reverseString(self): return self.data[::-1] if __name__=='__main__': #declare object myClass=MyClass("Life is very easy Python") #use object myClass.showSring() print myClass.reverseString()
Output:
Life is very easy Python nohtyP ysae yrev si efiL
0 comments:
Post a Comment