1. 程式人生 > >Python學習筆記(2.1)函數參數練習

Python學習筆記(2.1)函數參數練習

col python學習 nbsp cnblogs print item info inf --

  • 關鍵字參數 和 命名關鍵字參數
# -*- coding: utf-8 -*-

def print_scores(**kw):
    print(         Name    Score)
    print(-----------------------)
    for name, score in kw.items():
        print(   %10s      %d % (name, score))
    print()

print(print_scores(Adam=99, Lisa=88, Bart=77))

data 
= { Adam Lee: 99, Lisa S: 88, F.Bart: 77, } print_scores(**data) def print_info(name, *, gender, city=Beijing, age): print(Personal Info) print(---------------) print( Name: %s % name) print( Gender: %s % gender) print( City: %s % city)
print( Age: %s % age) print() print_info(Bob, gender=male, age=20) print_info(Lisa, gender=female, city=Shanghai, age=18)

Python學習筆記(2.1)函數參數練習