Python | Function handling mutable and immutable

Published: 23 March 2020
on channel: Florence Sharmila
46
1

How does the function handles when passed mutable and immutable datatypes as the parameters:

Case1:
def china(a):
print("Inside China\n")
print("Values recieved in side china",a)
a=a+2
print("values after change inside china()",a)
main
num= 3
print("Calling china(), passing", num)
china(num)
print("Back from china(), num value in global scope

Case2:
def china(ChinaList):
print("Inside China\n")
print("Values recieved in side china",ChinaList)
ChinaList.append(2)
ChinaList.extend([5,1])
ChinaList.remove(5)
print("values after change inside china()",ChinaList)
main
IndiaList=[1]
print("Before Calling china(), passing", IndiaList)
china(IndiaList)
print("Back from china(), num value in global scope ", IndiaList)

Case3:
def china(ChinaList):
print("Inside China\n")
print("Values recieved in side china",ChinaList)
ChinaList.append(2)
ChinaList.extend([5,1])
ChinaList.remove(5)
print("values after change inside china()",ChinaList)
main
IndiaList=[1]
print("Before Calling china(), passing", IndiaList)
china(IndiaList)
print("Back from china(), num value in global scope ", IndiaList)


On this page of the site you can watch the video online Python | Function handling mutable and immutable with a duration of hours minute second in good quality, which was uploaded by the user Florence Sharmila 23 March 2020, share the link with friends and acquaintances, this video has already been watched 46 times on youtube and it was liked by 1 viewers. Enjoy your viewing!