min and max, can receive any number of arguments. min's documentation states that min has two required parameters (named arg1 and arg2) and an optional third parameter of the form *args, indicating that the function can receive any number of additional arguments. * before the parameter name tells Python to pack any remaining arguments into a tuple that’s passed to the args parameter.average function that can receive any number of arguments.def average(*args):
return sum(args) / len(args)
*args parameter must be the rightmost parameter. average(5, 10)
average(5, 10, 15)
average(5, 10, 15, 20)
* operator, when applied to an iterable argument in a function call, unpacks its elements. grades = [88, 75, 96, 55, 83]
average(*grades)
average(88, 75, 96, 55, 83).©1992–2020 by Pearson Education, Inc. All Rights Reserved. This content is based on Chapter 4 of the book Intro to Python for Computer Science and Data Science: Learning to Program with AI, Big Data and the Cloud.
DISCLAIMER: The authors and publisher of this book have used their best efforts in preparing the book. These efforts include the development, research, and testing of the theories and programs to determine their effectiveness. The authors and publisher make no warranty of any kind, expressed or implied, with regard to these programs or to the documentation contained in these books. The authors and publisher shall not be liable in any event for incidental or consequential damages in connection with, or arising out of, the furnishing, performance, or use of these programs.