1. 程式人生 > >函式的多型別傳值

函式的多型別傳值

如下:

#!/usr/bin/env python

def fun(x, y):
    print(x+y)

fun(2, 3)        # 把數值型別作為引數傳入函式
 
fun('a', 'b')    # 把字串型別作為引數傳入函式

t = (2, 3)       # 把元組型別作為引數傳入函式
fun(*t)

dic = {'x':2, 'y':3}   # 把字典型別作為引數傳入函式
fun(**dic)