今天就学习课程吧!
今天就开通帐号,24,600 门业界名师课程任您挑!
Variable argument lists
- [Narrator] Just like some other programming languages, Python functions support variable argument lists and this makes it possible to build functions that have a high degree of flexibility by accepting different numbers of parameters. A good example of this might be an addition function that adds up the parameters passed to it. Now it would be pretty inconvenient to require cause of this function to have to conform to putting all the numbers into a list. So defining the function to accept a variable list of parameters would be a better way to go. To do this in Python, you define the function argument using an asterisk character in front of the parameter that you want to make variable. This parameter has to come after all the other positional parameters that the function defines. For example, if we built a logging function that logged messages along with parameter values, we would maybe first define the parameters for the message type and the message and then specify the variable…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。