python self-less

后端 未结 3 1789
一个人的身影
一个人的身影 2021-01-22 05:03

this works in the desired way:

class d:
    def __init__(self,arg):
        self.a = arg
    def p(self):
        print \"a= \",self.a

x = d(1)
y = d(2)
x.p()
y         


        
3条回答
  •  情歌与酒
    2021-01-22 05:32

    "self" is the way how Python works. So the answer is: No! If you want to cut hair: You don't have to use "self". Any other name will do also. ;-)

提交回复
热议问题