Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.4 kB
9
Indexable
Never
# In python in case of int value 0 to 255 - can be considered in memory optimisation
a = 2561
b = 2561
print(id(a))
print(id(b))


-------------------------------------------------------------------------------------

a = 1000
b = 1000
print(id(a))
print(id(b))

-------------------------------------------------------------------------------------

# memory optimisation

#refrence variable 

A.Pass by refrence 

------>A   ----->B = #2595177051216   ------->C = 10  #2595177051216


-------------------------------------------------------------------------------------

class Customer:
    def __init__(self,name):
        self.name = name 

cust = Customer('Radha')
print(cust.name)

-------------------------------------------------------------------------------------

class Customer:
    def __init__(self,name):
        self.name = name 

def greet(customer):
    print("Hello",customer.name)
    #return customer.name


cust = Customer('Radha')
cust2 = Customer('adi')

greet(cust)
greet(cust2)

-------------------------------------------------------------------------------------

class Customer:
    def __init__(self,name,gender):
        self.name = name
        self.gender = gender

def greet(customer):
    if customer.gender == "Male":
        print("Hello",customer.name,"Sir")
    else:
        print("Hello",customer.name,"Mam")

cust = Customer('Radha',"lady")

greet(cust)