python函数学习
Posted 一泽涟漪
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python函数学习相关的知识,希望对你有一定的参考价值。
函数定义和简单调用
公司新来部分新员工,定义函数并循环打印欢迎新员工的消息
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 !
函数使用默认值
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函数学习的主要内容,如果未能解决你的问题,请参考以下文章