Why does assigning to self not work, and how to work around the issue?

前端 未结 3 563
南旧
南旧 2020-12-11 21:04

I have a class (list of dicts) and I want it to sort itself:

class Table(list):
…
  def sort (self, in_col_name):
    self = Table(sorted(self,          


        
3条回答
  •  遥遥无期
    2020-12-11 21:54

    Python is pass by value, always. This means that assigning to a parameter will never have an effect on the outside of the function. self is just the name you chose for one of the parameters.

提交回复
热议问题