Python 'self' keyword

前端 未结 3 1768
小蘑菇
小蘑菇 2020-11-28 22:02

I am new to Python (usually work on C#), started using it over the last couple of days.

Within a class, do you need to prefix any call to that classes data members a

3条回答
  •  误落风尘
    2020-11-28 22:34

    There is no less verbose way. Always use self.x to access the instance attribute x. Note that unlike this in C++, self is not a keyword, though. You could give the first parameter of your method any name you want, but you are strongly advised to stick to the convention of calling it self.

提交回复
热议问题