1

Possible Duplicate:
What does *args and **kwargs mean?
Understanding kwargs in Python

I've found some strange syntax in Django framework like:

class Blog(models.Model):
    name = models.CharField(max_length=100)
    tagline = models.TextField()

    def save(self, *args, **kwargs):
        do_something()
        super(Blog, self).save(*args, **kwargs) # Call the "real" save() method.
        do_something_else()

My question is: what does the star means in the name of the argument. Is there anything with pointer in C? Thanks

Community
  • 1
  • 1
nam
  • 3,542
  • 9
  • 46
  • 68

2 Answers2

1

if you call save using these arguments:

save(1,2,3,4,a=20,b=30,c=40)

then args will be equal to (1,2,3,4) i.e. a Tuple and kwargs will be equal to {'a':20,'b':30,'c':40} a dictionary

these * and ** notations are used for collecting arguments in Python , they are not Pointers.

Ashwini Chaudhary
  • 244,495
  • 58
  • 464
  • 504
0

It's a python arguments syntax:

  • *args - list of unnamed arguments
  • **kwargs - dictionary (named arguments)