Why do you need explicitly have the “self” argument in a Python method?

前端 未结 10 1375
借酒劲吻你
借酒劲吻你 2020-11-22 11:53

When defining a method on a class in Python, it looks something like this:

class MyClass(object):
    def __init__(self, x, y):
        self.x = x
        se         


        
10条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 12:32

    Python doesn't force you on using "self". You can give it whatever name you want. You just have to remember that the first argument in a method definition header is a reference to the object.

提交回复
热议问题