Python交换两个变量值的函数

方法1:(错误)

def func(a,b):
    a,b = b,a

a = 1
b = 2
func(a,b)
print(a,"   ",b)

方法2:(正确)

def func(a,b):
    return b,a

a = 1
b = 2
a,b = func(a,b)
print(a,"   ",b)

 

posted @ 2018-09-02 15:30  清浅...忆回  阅读(2687)  评论(0编辑  收藏  举报