Python | Function handling mutable and immutable
Автор: Florence Sharmila
Загружено: 2020-03-23
Просмотров: 45
Описание:
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)
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: