如何将参数传递给函数?

时间:2015-04-05 05:41:47

标签: python-2.7

这是我的计划:

num1 = input ('Enter number1: ')
num2 = input ('Enter number2: ')
def swap_temp(a,b):
    print 'you are in swap_temp'
    temp = b
    b = a
    a = temp
    return(a,b)

def swap_notemp(num1,num2):
    print 'you are in swap_notemp'
    num1 = num1+num2;
    num2 = num1-num2;
    num1 = num1-num2;
    return(num1,num2)

num1,num2 = swap_notemp(num1, num2)
print ("now num1 ={0} and num2={1}".format(num1,num2))
print "now swap the numbers using temp variable"
num1,num2 = swap_temp(num1,num2)
print ("now num1 ={0} and num2={1}".format(num1,num2))

这是我的输出:

Enter number1: 1
Enter number2: 2
you are in swap_notemp
now num1 =2 and num2=1
'now swap the numbers with temp variable'
you are in swap_temp
now num1 =1 and num2=2

我想传递用户输入到swap_temp Func的相同值。我该怎么做?

0 个答案:

没有答案