What use adds a comma after its own argument in the class method?

In the code I'm looking at, I saw some class method similar to this:

class A(B):

    def method1(self,):
        do_something

    def method2(self,):
        do_something_else

Why does the author reserve a comma, what is its purpose?

+4
source share
1 answer

syntactically, the trailing comma is allowed , but it really means nothing. This is pretty much just a stylistic preference. I think most python programmers will not be able to disable it (this is a tip that I would also give), but some would prefer to make it easier to add extra arguments later.

. , :

x = foo(
    arg1=whatever,
    arg2=something,
    arg3=blatzimuffin,
)

:

lst = [x, y, z,]
tup = (x, y, z)
tup = x,  # Don't even need parens for a tuple...

, :

{
    "top": [
        "foo",
        "bar",
        "baz",
    ],
    "bottom": [
        "qux",
    ],
}

, / 1 , 2.

+5

Source: https://habr.com/ru/post/1537445/


All Articles