Python 練習(xí)實例47
python 練習(xí)實例47
題目:兩個變量值互換。
程序分析:無
程序源代碼:
實例:
#!/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))
以上實例輸出結(jié)果為:
x = 10,y = 20 x = 20,y = 10