Does it make a difference using self for a temporary variable in a Python method?

前端 未结 4 586
独厮守ぢ
独厮守ぢ 2021-01-06 02:27

I sometimes need to use temporary variables in method definitions that aren\'t used outside the method. Is there any difference in behaviour between using self.MyVaria

4条回答
  •  心在旅途
    2021-01-06 03:16

    The first usage would surprise me if I were looking at your code since it would make me think the variable was being used somewhere else in the class.

    Since the first is surprising and makes your intent harder to discern, I'd say the latter is more pythonic, and better in any language that works more or less the same way.

提交回复
热议问题