Answers for "argument in python"

9

python arguments

import sys

print ("the script has the name %s" % (sys.argv[0])
Posted by: Guest on November-18-2019
0

args in python

# if args is not passed it return message
# "Hey you didn't pass the arguements"

def ech(nums,*args):
    if args:
        return [i ** nums for i in args]  # list comprehension
    else:
        return "Hey you didn't pass args"
    
print(ech(3,4,3,2,1))
Posted by: Guest on June-24-2021
0

args in python

def func(*args):
    x = []          # emplty list
    for i in args:
        i = i * 2
        x.append(i)  
        y = tuple(x) # converting back list into tuple
    return y
        
tpl = (2,3,4,5)        
print(func(*tpl))
Posted by: Guest on June-24-2021
0

args in python

# if args is not passed it return message
# "Hey you didn't pass the arguements"

def ech(num,*args):  
    if args:
        a = []
        for i in args:
            a.append(i**num)
        return a                 # return should be outside loop
    else:
        return "Hey you didn't pass the arguements"     # return should be outside loop
    
print(ech(3))
Posted by: Guest on June-24-2021
0

args in python

# normal parameters with *args

def mul(a,b,*args): # a,b are normal paremeters
    multiply = 1
    for i in args:
        multiply *= i
        
    return multiply

print(mul(3,5,6,7,8))   # 3 and 5 are being passed as a argument but 6,7,8 are args
Posted by: Guest on June-24-2021
0

args in python

def add(*args):
    total = 0
    for i in args:
        total += i
    
    return total

print(add(5,5,10))
Posted by: Guest on June-24-2021

Python Answers by Framework

Browse Popular Code Answers by Language