-1

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?

Flux
  • 9,805
  • 5
  • 46
  • 92
ih s
  • 71
  • 7

3 Answers3

3

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?

Flux
  • 9,805
  • 5
  • 46
  • 92
1

The trailing comma makes no difference in parameter lists (though it is a syntax error in Python 3.5 and earlier).

For multi-line parameter lists, I prefer to have trailing commas on each line to make diffs smaller and more uniform.

AKX
  • 152,115
  • 15
  • 115
  • 172
1

There is no difference between (self) and (self,).

The main advantages are that it makes multi-line lists easier to edit and that it reduces clutter in diffs.

Check this link :- Why are trailing commas allowed in a list?

Akhil Pathania
  • 542
  • 2
  • 5
  • 19