Python 'self' keyword

前端 未结 3 1738
小蘑菇
小蘑菇 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:35

    First, Python's self is not a keyword, it's a coding convention, the same as Python's cls.

    Guido has written a really detailed and valuable article about the origin of Python's support for class, and in that article, Guido explains why use self and cls, and why they are necessary.

    See http://python-history.blogspot.com/2009/02/adding-support-for-user-defined-classes.html.

提交回复
热议问题