Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Using *args to pass the variable-length arguments to the function

# Welcome to softhunt.net
def adder(*num):
    sum = 0
    
    for n in num:
        sum = sum + n

    print("Sum:",sum)

adder(5,8)
adder(6,7,8,9)
adder(11,12,13,14,15)
Comment

variable-length arguments(*args)

# function with variable-length arguments
def percentage(*args):
    sum = 0
    for i in args:
        # get total
        sum = sum + i
    # calculate average
    avg = sum / len(args)
    print('Average =', avg)

percentage(56, 61, 73)
Comment

PREVIOUS NEXT
Code Example
Python :: using format str with variable 
Python :: pass method 
Python :: pthalic acid 
Python :: prolog split list positive negative 
Python :: jdoodle python 
Python :: plt hist random normal distribution 
Python :: velocity field gradient 
Python :: docstring return list of tuple 
Python :: convert a float array to an integer 
Python :: Annotation graphique python 
Python :: Find element with class name in requests-html python 
Python :: Broadcasting with NumPy Arrays Plotting a two-dimensional function Example 
Python :: Python NumPy Shape function example Printing the shape of the multidimensional array 
Python :: python f strings 
Python :: smile detection 
Python :: Python NumPy block Function Syntax 
Python :: making dividers in tkinter 
Python :: how to add to an exsiting value of an index in a list 
Python :: Python __div__ magic method 
Python :: Program to get number of consecutive repeated substring 
Python :: sourcetrail index library python 
Python :: ROS subscribes to image type video frames (Python) through topic Publishing 
Python :: downsample audio 
Python :: send http request from python with quesry 
Python :: knn compute_distances_no_loop 
Python :: Compress multiple directories but exclude directory - Python zipfile(or anything native to Windows 2012+ 
Python :: python code sample submission of codeforces 
Python :: corpus.fit(sentences, window=10) 
Python :: python logical operators code in grepper 
Python :: python without creating pyc 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =