Python - Is it okay to pass self to an external function

前端 未结 1 1435
后悔当初
后悔当初 2021-02-03 18:06

I have a class, A, which is inherited by a bunch of other classes. Some of these have a few functions which are similar and it would be nice to have those functions defined some

相关标签:
1条回答
  • 2021-02-03 18:11

    There is no problem with that whatsoever - self is an object like any other and may be used in any context where object of its type/behavior would be welcome.

    In Python, as exemplified by the standard library, instances of self get passed to functions (and also to methods, and even operators) all the time.

    0 讨论(0)
提交回复
热议问题