and keyword arguments. ... """ ... print(’arg1: {0}, arg2: {1}, ’ ... ’kwarg1: {2}, kwarg2: {3}’ ... .format(arg1, arg2, kwarg1, kwarg2)) ... print(’args:’, repr(args)) ... print(’kwargs:’, repr(kwargs)) >>> f.__name__ 235 >>> dir() 236 >>> f.__name__ = ’g’ 237 >>> dir() 238 >>> f.__name__ 239 >>> f 240 >>> f.func_dict 241 >>> f.foo = ’bar’ 242 >>> f.func_dict 243 >>> f.func_defaults 244 >>> f(1, 2) 245 >>> f(arg1=1, arg2=2) 246 >>> f(arg2=1, arg1=2) 247 >>> f(1, 2, 3) 248 >>> f(1, 2, kwarg2=4) 249 >>> f(1, kwarg1=3) 250 >>> f(1, 2, 3, 4, 5, 6) 251 >>> f(1, 2, 3, 4, keya=7, keyb=8) 252 >>> f(1, 2, 3, 4, 5, 6, keya=7, keyb=8) 253 Exercises: Functions >>> def f(a1, a2, kw1=’k1’, kw2=’k2’): 254 ... print(repr((a1, a2, kw1, kw2))) >>> f(1) 255 >>> f(1, 2) 256 >>> f(1, 2, 3) 257 >>> t = 1, 2 258 >>> t 259 >>> d = dict(kw1=3, kw2=4) 260 >>> d 261 >>> f(*t) 262 >>> f(**d) 263 >>> f(1, 2, **d) 264 >>> f(*t, **d) 265 11