*args tests

This commit is contained in:
David Halter
2012-05-06 01:03:47 +02:00
parent cb5b036f01
commit 40e59c0476
3 changed files with 50 additions and 8 deletions

View File

@@ -168,13 +168,13 @@ class C(object):
def c_a(self):
self.c_b = 1
test = [1,2]
def args_func(arg1, *args, **kwargs):
return (arg1, args)
def args_func(arg1=0, *args, **kwargs):
return arg1
return args
#? ['real']
exe = args_func(list,"", 3)
args_func(1,"", a=list)[0].
args_func().; C().
args_func(arg1=0, *test + [3], *[4,5], **{'a': 'b'}).
exe[1].

View File

@@ -116,3 +116,9 @@ f1.
#? []
g1.
# -----------------
# dicts
# -----------------
dic2 = {'asdf': 3}
#? ['real']
dic2['asdf'].real

View File

@@ -69,11 +69,47 @@ def a():
l.real
# -----------------
# *args / ** kwargs
# *args
# -----------------
def args_func(*args):
return args
exe = args_func(1, "")
#? ['real']
args_func(1)[0].real
exe[0].real
#? []
exe[0].upper
#? []
exe[1].real
#? ['upper']
exe[1].upper
def args_func(arg1, *args):
return arg1, args
exe = args_func(1, "", list)
#? ['real']
exe[0].real
#? []
exe[0].upper
#? []
exe[1].real
#? ['index']
exe[1].index
#? []
exe[1][1].upper
#? ['append']
exe[1][1].append
# -----------------
# ** kwargs
# -----------------
# -----------------
# *args / ** kwargs
# -----------------