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

形参和实参的区别?

举个例子

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 + ' ')
    print(username)
 
employee('man''tom''jerry')

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

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

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

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