Search code examples
pythonclassmethodsdefinitionself

What is the difference between (self) and (self,) in python method?


method in class of M2DET published

Let's see a code sentence def consturct_modules(self,):.

I have a simple question about why this method defines (self) as (self,).

It seems to me that (self) is proper form.

What is the difference?


Solution

  • No difference in terms of function. Trailing comma in function argument lists is allowed starting from Python 3.6. See: https://bugs.python.org/issue9232

    In terms of style, the trailing comma is not recommended in this particular case. See: Should I add a trailing comma after the last argument in a function call?