/ Python And R Data science skills: 07 about self parameter in Telugu

Saturday, 17 February 2018

07 about self parameter in Telugu

07 about self parameter
In [51]:
class ram:
    def my(a):
        a.name="kumar"
        print(a.name)
    def m1(a):
        print(a.name)
  
ram1=ram()
ram1.my()
ram1.m1()
#ram.my(ram1)
kumar
kumar
In [27]:
class ram:
    def my(self ):
        self.name="kumar"
        print(self.name)
        age=33
        print(age)
    def my1(self ):
        
        print(self.name)
       
        print(age)
       
ram1=ram()
ram1.my()
#ram2=ram()
ram1.my1()
kumar
33
kumar
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-27-73fbed5da1c1> in <module>()
     14 ram1.my()
     15 #ram2=ram()
---> 16 ram1.my1()

<ipython-input-27-73fbed5da1c1> in my1(self)
      9         print(self.name)
     10 
---> 11         print(age)
     12 
     13 ram1=ram()

NameError: name 'age' is not defined
In [26]:
class ram:
    def my(self ):
        self.name="kumar"
        print(self.name)
        self.age=33
        print(self.age)
    def my1(self ):        
        print(self.name)       
        print(self.age)
       
ram1=ram()
ram1.my()
#ram2=ram()
ram1.my1()
kumar
33
kumar
33

No comments:

Post a Comment