- 预设值问题
def function(p1,p2,...pi=default1...pn=defaultn)
s1
s2
...
return v1,v2,v3
预定义值的参数写在括号右侧,不能这样写“test_e(n1=1,n2)”
# -*- coding: cp936 -*- def test_a():#函数定义,无参,无返回值 print ' Hello the bling' print ' www.bling.com' def test_b(p1,p2):#函数定义,形参 print p1, print p2 def test_c(p1,p2):#函数定义,形参,有返回值 print p1, print p2 p = p1+p2 return p def test_d(p1,p2):#函数定义,形参,有返回值 print p1, print p2 n = p1+p2 m = p1*p2 e = p1**p2 p = p1-p2 return n,m,e,p def test_e(p1,p2 = 15):#函数定义,形参,有返回值,预定义值 print p1, print p2 p = p1+p2 return p print 'Entry programme' test_a() test_b('yml',',jun')#函数调用,实参 test_b(11,13) sum = test_c(20,21) print 'sum = ',sum sum1,muti,pow,plus = test_d(2,10) print sum1,muti,pow,plus re = test_d(2,10) print re[0],re[1],re[2],re[3] s = test_e(10) print s s1 = test_e(10,20) print s1 print 'Leave programme' #输出 Entry programme Hello the bling www.bling.com yml ,jun 11 13 20 21 sum = 41 2 10 12 20 1024 -8 2 10 12 20 1024 -8 10 15 25 10 20 30 Leave programme