Python 47
[Python 100] Python 100
#!/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))
# -*- 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))
x = 10,y = 20 x = 20,y = 10
[Python 100] Python 100
252***[email protected]
#!/usr/bin/env python3 # -*- coding: utf-8 -*- def exchange(a, b): print(' = {}, = {}'.format(a, b)) a, b = b, a print(' = {}, = {}'.format(a, b)) if __name__ == '__main__': x = 1 y = 8 exchange(x, y)252***[email protected]
114***[email protected]
#!/usr/bin/python # coding:utf-8 a = int(raw_input("a: ")) b = int(raw_input("b: ")) a = a + b b = a - b a = a - b print "a=%s b=%s" % (a, b)114***[email protected]
253***[email protected]
Python3
#!/usr/bin/python3 a,b,c=1,2,0; c=a;a=b;b=c; print('a=',a,'\nb=',b)253***[email protected]
Webben
wei***[email protected]
Webben
wei***[email protected]
chengxuyuan
hdw***[email protected]
# encoding:utf-8 ''' —— ''' def shuru(): a = raw_input('a') b = raw_input("b") return a, b def change1(a, b):# t = a a = b b = t print ',a,b', a, b def change2(a, b):# a = a + b b = a - b a = a - b print ',a,b', a, b def change3(a, b):# la = len(a) a += b b = a[0 : la] a = a[la : ] print ',a,b', a, b,type(a) a, b = shuru() change1(a, b) change2(int(a), int(b)) change3(str(a), str(b))chengxuyuan
hdw***[email protected]
475***[email protected]
python3:
475***[email protected]