python参数传递是值传递还是引用传递
1个回答
展开全部
那要看数据类型了,int,float,str这种就是传值,list,dict,类的实例,自定义对象都是穿引用。
下面是示例代码:def change(int1,float1,str1,dict1,obj1,list1): int1+=1 float1+=1 str1+='changed' dict1['none_exist_key']='none_exist_value' obj1=None list1.append('change')class obj: passint1=0float1=0.0str1='origin'dict1={'key':'value'}obj1=obj()list1=['only_element']print(int1)print(float1)print(str1)print(dict1)print(obj1)print(list1)change(int1,float1,str1,dict1,obj1,list1)print('after change')print(int1)print(float1)print(str1)print(dict1)print(obj1)print(list1)
下面是示例代码:def change(int1,float1,str1,dict1,obj1,list1): int1+=1 float1+=1 str1+='changed' dict1['none_exist_key']='none_exist_value' obj1=None list1.append('change')class obj: passint1=0float1=0.0str1='origin'dict1={'key':'value'}obj1=obj()list1=['only_element']print(int1)print(float1)print(str1)print(dict1)print(obj1)print(list1)change(int1,float1,str1,dict1,obj1,list1)print('after change')print(int1)print(float1)print(str1)print(dict1)print(obj1)print(list1)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询