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

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

how to have unlimited parameters in a function in python

# to pass unlimited parameters add one astors
# this method is for positional arguments
def add(*numbers):
    total = 1
    for number in numbers:
        total += number
    return total

print(add(1, 2, 3, 4, 5)) # add as many as you want

# Output >>> 16
Comment

PREVIOUS NEXT
Code Example
Python :: pandas append index ignore 
Python :: import matplotlib 
Python :: wikipedia python 
Python :: removing features pandas 
Python :: how to remove blank lines from string in python 
Python :: how to create requirements.txt django 
Python :: py how to deactivate venv 
Python :: horizontal bar plot python 
Python :: how many days until 2021 
Python :: discord.py send messages 
Python :: extract column numpy array python 
Python :: numpy array equal 
Python :: use datetime python to get runtime 
Python :: how to shutdown a windows 10 computer using python 
Python :: numpy generate random 2d array 
Python :: python requests port 
Python :: copy a list python 
Python :: Write a python program to find the most frequent word in text file 
Python :: extract url from page python 
Python :: equal sides of an array python 
Python :: pandas remove column 
Python :: how to check if a letter is lowercase in python 
Python :: datetime to unix timestamp milliseconds python 
Python :: check if string has digits python 
Python :: filter list of tuples python 
Python :: python 3.9 features 
Python :: python [remote rejected] master - master (pre-receive hook declined) 
Python :: create 2d array python list comprehension 
Python :: python regex get string before character 
Python :: discord music queue python 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =