首页 > 编程语言 > 详细

Python学习笔记(2.1)函数参数练习

时间:2017-08-08 23:55:49      阅读:326      评论:0      收藏:0      [点我收藏+]
  • 关键字参数 和 命名关键字参数
# -*- 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)函数参数练习

原文:http://www.cnblogs.com/douzujun/p/7309494.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!