#!/usr/bin/env python
#个人学习笔记, no other use
def add (x=9,y=10):
if x>y:
a=x+y
print "X+y"
return A
if x<y:
a=y-x
print "Y-x" return
a
if x==y:
a=x*y
print "X*y" return
A Print Add (2,3) print add (
5,4)
print Add (6,6)
Pass the value of an array to the function
#!/usr/bin/env python
t= (' name ', ' Tom ')
def f (x,y):
print "%s:%s"% (X,y)
f (1,2)
f (*t)
Passing the value of a dictionary to a function
#!/usr/bin/env python
d={' age ': ' Name ': ' Tom '}
def f (name= ' Lisa ', age=23):
print ' name---%s '% name
print ' age----%s '% Age
f (**d)
#如果是一个 *, passing the key in the dictionary, two * *, passing the value in the dictionary
Handling Redundant parameter Passes
#!/usr/bin/env python
def f (x,*args):
print x
print args
f (1,2,3,4)
#结果显示为
1 (2, 3, 4) # 2,3,4 as a whole passed to args.
def m (x,*args,**kwords):
print x
print args
print kwords
m (1,2,3,4,5,args=2)
#运行结果
1 (2 , 3, 4, 5) {' Args ': 2}