0

Is there any hierarchy to pass arguments in python..?

>>>def anyFun(a,tuple,dictionary)

Should we pass int/str then tuple and then dictionary.

>>>def anyFun1(dictionary,tuple,a)

Should we pass int/str then dictionary and then tuple

>>>def anyFun2(tuple,a,dictionary)

Should we pass tuple then int/str and then dictionary.

or we can pass the arguments in python as in other programming languages. Please help me on this .

2 Answers 2

1

My experience is python is quite limited. But as far as I know, the order you pass the arguments to a function won't really 'cause any major effects.

2
  • There is a difference if we do not pass the argument in proper sequence .
    – Sanyal
    Sep 7, 2015 at 13:36
  • 1
    @bittu sorry wrong choice of words. What I meant is that the order of arguments to be passed when we define a function doesn't matter. Whether we define our function to accept a tuple or an int first doesn't matter.
    – J.Alvaro.T
    Sep 21, 2015 at 10:22
0
have a function with arguments as Tuple and Dictionary:
def fo(*args,**li):
     print args
     print "args is of type:",type(args)#->is a tuple
     print li 
     print "**li is of type:",type(li) #-> ** is dictionary 
fo( a=8,b=9,c='as',1,3,4,)
Output : Will throw an error 

Correct way to pass an argument(in this case Tuple and Dictionary) :
fo(1,3,4, a=8,b=9,c='as')
Output: 
(1, 3, 4)
args is of type: <type 'tuple'>
{'a': 8, 'c': 'as', 'b': 9}
**li is of type: <type 'dict'>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.