首页 > 编程语言 > 详细

【python3】第8~9章函数、类

时间:2020-07-08 17:48:29      阅读:69      评论:0      收藏:0      [点我收藏+]

形参和实参的区别?

举个例子

def employees(username):

    print(username)

employees(‘Tom‘)

其中username就是形参,Tom是实参。形参是一个函数需要使用的参数,而实参是则是这个参数具体的值或信息。

 

多种传递参数的方式

传递单个实参
def employee(username):
    print(username)
 
employee(‘Tom‘)
传递任意数量的实参
def employee(*username):
    print(username)
 
employee(‘Tom‘‘jerry‘‘cat‘)

技术分享图片

 

单个实参和多个实参的传递的正确传递
def employee(sex, *username):
    print(sex + ‘\n‘)
    print(username)
 
employee(‘man‘‘tom‘‘jerry‘)

技术分享图片

 

单个实参和多个实参的传递的错误传递
def employee(*username, sex):
    print(sex + ‘\n‘)
    print(username)
 
employee(‘man‘‘tom‘‘jerry‘)

技术分享图片

 

传递任意数量的关键字实参
def user_profile(first, last, **user_info):
    print(first + last + ‘的信息:‘)
    print(user_info)
 
user_profile(‘张‘‘三‘, sex=‘男‘, age=19)

技术分享图片

 

继承、多态等会在其他知识点实际运用

【python3】第8~9章函数、类

原文:https://www.cnblogs.com/CSgarcia/p/13267918.html

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