Python 練習(xí)實(shí)例47
題目:兩個(gè)變量值互換。
程序分析:無
程序源代碼:
#!/usr/bin/python # -*- coding: UTF-8 -*- def exchange(a,b): a,b = b,a return (a,b) if __name__ == '__main__': x = 10 y = 20 print 'x = %d,y = %d' % (x,y) x,y = exchange(x,y) print 'x = %d,y = %d' % (x,y)
以上實(shí)例輸出結(jié)果為:
x = 10,y = 20 x = 20,y = 10
更多建議: