码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2017-08-09 00:08:20      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:int   nbsp   div   函数   lis   odi   beijing   isa   strong   

  • 关键字参数 和 命名关键字参数
# -*- 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)函数参数练习

标签:int   nbsp   div   函数   lis   odi   beijing   isa   strong   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!