'''class person: def __init__(self,fname,lname): self.fname=fname self.lname=lname self.fullname=f"{self.fname} {self.lname}" #derived from above attributes not from object arguments p1=person("N","Harish") #object print(p1.fullname) p1.fname="software" #here i can change fname and lname print(p1.fname) print(p1.fullname) #fname changed but full name was not changed because it is not came from object arguments ''' #_______________________________________________________________________ # using property decorator we change directly the attribute see below code class person: def __init__ ( self , fname , lname): self .fname=fname self .lname=lname @property #due to this i can call fullname function as attribute that is without () after function def fullname ( self ): #getter if self .fname== None or self .lname== None : return "fullname was dele...
# '==' : value equality-two objects have the same value # is : reference equality- two references refer to the same object a=[ 1 , 2 , 3 ] b=a #two references refer to the same object(b is not the copy of a) print (b==a) print (b is a) c=a[:] #two references refer to the two different object(now c is the copy of a) print (c==a) print (c is a)
Comments
Post a Comment