*args in Python - Python Automation and Machine Learning for ICs - - An Online Book - |
||||||||
Python Automation and Machine Learning for ICs http://www.globalsino.com/ICs/ | ||||||||
================================================================================= | ||||||||
============================================ *args in Python allows you to pass multiple, varying arguments or keyword arguments to a function. args is just a name. You’re not required to use the name args. You can choose any name that you prefer. "*" is the unpacking operator. Simple function: code: ============================================ Sum a list of numbers in any length: code: Check if all the characters in the text are numeric or not: code: ============================================ Calculate the arbitrary number of variables: code: ============================================ Variable number of input arguments: code: ============================================ Sum the numbers of a defined list: code: ============================================ Sum the numbers of a varying list: code: Use decorators: code: ============================================ Access a function variable from outside with a function decorator (but makes the code hard to maintain): Code:
|
||||||||
================================================================================= | ||||||||
|
||||||||