0

I am new to Python OOP.

Consider this code snippet below:

class LinearTopo(Topo):

    def __init__(self, k=2, **opts):
        Topo.__init__(self, **opts)
        ...
        ...


LinearTopo(k=4) # Not passing the **opts argument

I believe, **opts is an essential argument which is needed for creating an object of class LinearTopo. However, Python allows to create objects of class LinearTopo without this argument. Could someone explain, how it is possible ?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
nitin_cherian
  • 6,405
  • 21
  • 76
  • 127
  • `**opts` captures **zero or more** keyword arguments. Zero keyword arguments is perfectly legal. Why do you think it is required? – Martijn Pieters Jun 03 '14 at 17:10
  • Note that even if nothing is passed as argument, `opts` exists in the function (it's the dictionary `{}`). –  Jun 03 '14 at 17:12

0 Answers0