函式 - 串列應用與任意數量的引數
· 9 min read
傳入串列
函式傳入串列是很好用的功能,把串列傳入函式後,函式就能直接存取其內容。
假設有個使用者串列,我們要對串列中每位使用者輸出問候文字:
def greet_users(names):
"""Print a simple greeting to each user in the list."""
for name in names:
msg = "Hello, " + name.title() + "!"
print(msg)
usernames = ['hannah', 'ty', 'margot']
greet_users(usernames)
