可變長度的參數傳遞
def p(fmt, *arg):
print fmt % arg
# 傳多個參數
s1 = "hello"
s2 = "world"
p("%s %s", s1, s2)
# 把 list 的 element 當作參數
l = ["Allen", "Billy", "Elmer"]
p("%s %s %s", *tuple(l))
# 混合模式
l = ["Allen", "Billy", "Elmer"]
s = "hello"
p("%s, %s %s %s", *((s, ) + tuple(l)))
Output:
hello world Allen Billy Elmer hello, Allen Billy Elmer