Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

unlimited arguments python

def add(*args):		# *args takes multiple inputs
  return sum(args)


print(add(1,2,3,4,5))    # prints 15
print(add(10, 20, 30))	 # prints 60
Comment

unlimited keyword arguments python

def calculate(n, **kwargs):
  print(n + kwargs['add'])
  print(n * kwargs['multiply'])


calculate(3, add=4, multiply=5)
Comment

how to make it so we can give unlimited parameters in python function

def average2(*args):
    listofvalues = []
    for item in args:
        listofvalues.append(item)
    return sum(listofvalues) / len(listofvalues)
Comment

PREVIOUS NEXT
Code Example
Python :: install python 3.9 linux 
Python :: convert mp3 to wav python 
Python :: python3 base64 encode basic authentication 
Python :: how to print image with cv2 
Python :: pytest --clrear cache 
Python :: python perfect square 
Python :: how to save matplotlib figure to png 
Python :: run celery on windows 
Python :: change directory in python os 
Python :: conda python 3.8 
Python :: how to get specific row in pandas 
Python :: how to get random word from text file in python 
Python :: clear console python 
Python :: remove web linnks from string python 
Python :: split a path into all subpaths 
Python :: how to get a random element from an array in python 
Python :: how to install flask module in vscode 
Python :: no python 3.10 installation was detected 
Python :: insertion sort python 
Python :: python split range equally 
Python :: How to Add a Title to Seaborn Plots 
Python :: installing wxpython on windows 10 
Python :: os get current directory 
Python :: f-string ponto decimal python 
Python :: how to pause code for some time in python 
Python :: bgr to gray opencv 
Python :: merge pdf in python 
Python :: python requests.get timeout 
Python :: display max rows pandas 
Python :: how to save a model and reuse fast ai 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =