Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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 :: Mapping using dictionary 
Python :: Insert datframe column at specific place 
Python :: Custom x, y-ticks using ax 
Python :: iterate over batch of dict keys at once python 
Python :: upload file to SQL server pyodbc python 
Python :: Delete files in folder by extension 
Python :: Pandas: Ternary conditional operator for setting a value in a DataFrame 
Python :: Creaing your own functions 
Python :: matrix of matrices python grepper 
Python :: theano_flags windows 
Python :: python pid control 
Python :: np choose explain 
Python :: how to get a rectangular grid out of two given one-dimensional arrays 
Python :: automation script for paytm coupon 
Python :: lambda if else nothing python 
Python :: how to maximize pandas output python 
Python :: Python Script to check how many images are broken 
Python :: how to dynamically search for a class variable in python 
Python :: How to create an AI from scratch 
Python :: name decorator in python 
Python :: add up all the numbers in each row and output that number output the grand total of all rows 
Python :: Compute the variance of this RDD’s elements 
Python :: python loop over s3 objects] 
Python :: python pygeoip example 
Python :: restore tf model python ValueError: Unknown loss function:smoothL1 
Python :: how to see a full row in pandas 
Python :: tensorflow albumentations object detection 
Python :: get a liste from a txt file python 
Python :: for loop shorthand python 
Python :: python recall a line from a text file 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =