bonjour,
je n'arrive pas a retrouver comment on definit une fonction
avec un nombre de parametre variable.
genre:
je voudrais le meme resultat, mais avec un appel du style :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 def maFonction (arg=[], argv=[]): "" txt = "call: maFonction(" for k in range(len(arg)): if (k!=0): txt += ", " txt += arg[k] + "=" + str(argv[k]) txt += ")" print txt return None def maFonction2 (argDico={}): "" txt = "call: maFonction(" i = 0 for k in argDico.keys(): if (i!=0): txt += ", " i += 1 txt += k + "=" + str(argDico[k]) txt += ")" print txt return None maFonction() # call: maFonction() maFonction(["a", "b"], [1, 2]) # call: maFonction(a=1, b=2) maFonction2() # call: maFonction() maFonction2({"a":1, "b":2})# call: maFonction(a=1, b=2)
merci.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 maFonction(a=1, b=2)
Partager