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?
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?
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?
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.
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?