//fourth day to study python
24. In python , how to create funcation.
we can use def to define funcation. such as:
def MyFirstFuncation():
print('this is my first funcation')
MyFirstFuncation()
-> this is my first funcatio.
if there are no MyFirstFuncation , it will be have an error.
of course , we can pass a parameter
def MySecondFuncation(language):
print(' i love ' + language)
MySecondFuncation('python')
->i love python
if parameter is more , we can use comma divided parameter, such as:
def AddFuncation(num1,num2):
print(num1 + num2)
-> 3
how to use return:
def SubFuncation(num1,num2):
return (num1 - num2)
print(SubFuncation(6,3))
-> 3
ok , next to study
def myFuncation(m):
'do you know what is funcation'
#this is secret
print('my'+m+'roy')
myFuncation.__doc__
-> do you know what is funcation
next example:
def sortFuncation(str1,str2):
print(str1,str2)
sortFuncation('second','first')
-> second first
sortFuncation(str2 = 'second', str1 = 'first')
-> first second
default funcation:
def defaultFuncation(name='wyg',age='12'):
print(my name is '+name+'age is '+age)
defaultFuncation()
-> my name is wyg age is 12
def textPara(*paras):
print('parameters length is:',len(paras))
print('the second parameters is:',paras[1])
textPara(1,2,3,'roy')
->
parameters length is: 4
the second parameters is: 2
def textPara(*paras,exp):
print('parameters length is:',len(paras),exp)
print('the second parameters is:',paras[1])
textPara(1,2,3,'roy',exp = 6)
->
parameters length is: 4 6
the second parameters is: 2
//fifth day to study python(2016/8/6)
25. In python ,how to retu