2017年9月30日 星期六

Python - Function筆記

函式Function

宣告方式
def hello():
    print ('hello')

hello() # hello


設定引數
def hello(name):
    print('hello, {}'.format(name))

hello('Tom')


引數的預設值,呼叫function未設定引數
def hello(name='default'):
    print('hello, {}'.format(name))

hello()


function return值
def hello():
    return 'hello123'

h = hello()
print(h) # hello123

引數為*args時,為Tuple

引數為**args時,為Dictionary


沒有留言:

張貼留言