首页 > 编程语言 > 详细

python函数学习

时间:2019-12-14 14:59:18      阅读:89      评论:0      收藏:0      [点我收藏+]

函数定义和简单调用

公司新来部分新员工,定义函数并循环打印欢迎新员工的消息

employees = {"Chris": "NOC", "David": "PJM", "Brain": "SA", "John": "UX"}


def introduce_employee(employee, post):
    print("Welcome our new colleague " + username + ", his post is " + job + " !")


for key, value in employees.items():
    username = key
    job = value
    introduce_employee(username, job)

输出

技术分享图片
Welcome our new colleague Chris, his post is NOC !
Welcome our new colleague David, his post is PJM !
Welcome our new colleague Brain, his post is SA !
Welcome our new colleague John, his post is UX !
View Code

 函数使用默认值

def print_employees(employee, post="NOC"):
    print("Welcome our new colleague " + employee + ", his post is " + post + ".")


print_employees("David", "UX")
print_employees("Chris", "PJM")
print_employees("Brain")
print_employees("John")

 输出

Welcome our new colleague David, his post is UX.
Welcome our new colleague Chris, his post is PJM.
Welcome our new colleague Brain, his post is NOC.
Welcome our new colleague John, his post is NOC.

 

python函数学习

原文:https://www.cnblogs.com/ilifeilong/p/12038839.html

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