-1

based on this question... first answer...second code

Python -- Only pass arguments if the variable exists

is there a way I can handle any number of arguments even it is 12 for example ....

to make more clear...

if I have 10 optional parameter function and user didn't provide one argument or 9 argument it still work

( if A user didn't provide a parameter argument it will ignore that or any other optional arguments )

thank you ❤

paull
  • 15
  • 2
  • 7

2 Answers2

-1

I guess you are talking about this. Check this one out.

nagyl
  • 1,644
  • 1
  • 7
  • 18
-1

You can do something like this:

def name(arg1, *argv): 
    print ("First argument :", arg1) 
    for arg in argv: 
        print("Next argument through *argv :", arg)

name('arg1', 'arg2', 'arg3, 'arg4') 

Or create multiple functions with the same name but with different amounts of parameters. Then you can call these functions

def same_name(oneParam):
     #do something
    
def same_name(oneParam,secondParam):
    #do something else

same_name(oneParam = 'one')
same_name(oneParam = 'one',secondParam = 'two')
Dani
  • 556
  • 7
  • 23
  • look for example the print function in python after you type print function in python it will provide you with a list of parameters ... that exactly what I want – paull Jun 30 '20 at 13:04
  • In my first example, argv is a list of all the parameters entered – Dani Jun 30 '20 at 13:18
  • but how can I say if a user entered for example IMAGINE if sky ... it will make the text fly , ground for being floor... how to handle it ... and what if the .... for example .... for example in a function I make the parameter fly or not fly in 4th parameter and but in my function I defined for example in 3rd parameter....Do You Have a Topic Where I can read ... Just first explain How to the provide me a url where I can read from... your Answer stocked in my mind ... the second not the first one – paull Jun 30 '20 at 18:58