#函数, Method
#普通方法
def hello ():
print (' hello ')
Hello ()
#带形参的方法
def hello1 (name):
Print (' hello%s '%name)
Hello1 (' Brad Pitt ')
#多个参数的方法
def Hello2 (name1,name2):
Print (' hello%s and%s '% (name1,name2))
Hello2 (' Brad Pitt ', ' Dirk ')
#带默认值参数的方法
def hello3 (name1,name2,name3= ' Ferrari '):
print (' hello%s%s%s '% (name1, Name2,name3))
Hello3 (' Pete ', ' Dirk ',)
#可变参数的方法
def Hello4 (*args):
Print (args)
Hello4 (1,2,3,4)
# Keyword parameter, key v accepted in is a dictionary
def hello5 (**kwargs):
Print (Kwargs)
Hello5 (name= ' Qiao ', age=18)
a={' name ': ' Q ', ' Age ': '
Hello5 (**a)
#关键字传值
#关键字调用参数不用排序. Because the keyword
def hello6 (name,age) is specified:
Print (name,age)
Hello6 (age=1,name= ' Qiao ')
#函数 The return value of the method
Def plus (NUM1, NUM2):
Return num1,num2,num1+num2# encounters return immediate end, the following code does not go
print (plus (10,2))
A=plus (12,3)
Print (a[2]) # The return value is a tuple
#函数没有返回值时, which returns none
#传什么类型, returns what type
#局部变量, global variable
#如果在函数里修改全局变量, need to declare first, declare with global
Python Basic Operations _ Method (function)