在Python及其层次结构中传递参数

时间:2015-07-28 11:42:19

标签: python-2.7

是否有任何层次结构在python中传递参数..?

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

我们应该传递int / str然后传递tuple然后传递字典。

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

我们应该传递int / str然后传递字典然后传递

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

我们应该传递元组然后是int / str然后传递字典。

或者我们可以像在其他编程语言中一样传递python中的参数。 请帮帮我。

2 个答案:

答案 0 :(得分:1)

我的经验是python非常有限。但据我所知,将参数传递给函数的顺序确实不会造成任何重大影响。

答案 1 :(得分: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'>