1.

(r’^articles/(\d{4})/(\d{2})/$’, month_archive)

vs.

2.

(r’^articles/(?P<year>\d{4})/(?P<month>\d{2})/$’, month_archive)

The first one: positional argument

The second one: keyword argument

For example, a request to

/articles/2009/10/

would result in

1. month_archive (request, ’2009′,’10′)

2. month_archive(request, year=’2009′, month=’10′)

def func(*args, **kwargs):

Python functions and methods can pass and receive arguments in two forms:

1. positional argument (the order is important)

2. keyword argument(names along with the values)

In Python, list and dictionary types are used for positional and keyword arguments respectively.

Passing a list as an argument and prefixing it with a single asterisk(*) will cause each item of the list in order. This will be used as a separate positional argument.

Passing a dictionary and prefixing it two asterisks(**) will cause the keys of the dictionary to be used as names for separate keyword arugments and the dictionary’s values to become the values of these arguments.

© 2011 Web Oom Suffusion theme by Sayontan Sinha
Switch to our mobile site
Top Footer