Naming the self parameter something else

后端 未结 4 1919
花落未央
花落未央 2021-01-13 17:27

In Python, this code is valid:

class A:

    def __init__(me):
        me.foo = 17

    def print_foo(myself):
        print(myself.foo)

    def set_foo(i,          


        
4条回答
  •  [愿得一人]
    2021-01-13 17:55

    This blog post from Guido van Rossum explains a little around the subject. Spesifically:

    I see no reason with this proposal to make 'self' a reserved word or to require that the prefix name be exactly 'self'.

    It is just a convention, and it is nice to stick with it.

提交回复
热议问题