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

python函数学习

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

标签:定义函数   john   name   welcome   VID   style   code   打印   pos   

函数定义和简单调用

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

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函数学习

标签:定义函数   john   name   welcome   VID   style   code   打印   pos   

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

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