1

Possible Duplicates:
python ‘self’ explained
Why do you need explicitly have the “self” argument into a Python method?

Why does Python require the "self" parameter for methods?

For example def method_abc(self, arg1)

And is there ever a date that the need for it will be removed?

Community
  • 1
  • 1
TeddyB
  • 29
  • 1
  • 3
  • 1
    What is your suggestion for determining what name to refer to the current object as? – Anon. Aug 16 '10 at 01:20
  • See also: http://stackoverflow.com/questions/1984104, http://stackoverflow.com/questions/68282/, http://stackoverflow.com/questions/475871/, http://neopythonic.blogspot.com/2008/10/why-explicit-self-has-to-stay.html – sdcvvc Aug 16 '10 at 01:22
  • 1
    @Anon, "this" - just like in Java, that exists without needing to be defined. – TeddyB Aug 16 '10 at 01:42

1 Answers1

0

Python gives you the option of naming it something other than self, even though the standard is to name it self. Just as it gives you the option of using tabs for indents, even though the standard is to use spaces.

In other words, it's not just "assumed" because...

  1. To give you naming flexibility
  2. To make it clearer that something will be passed self (or not).
Amber
  • 507,862
  • 82
  • 626
  • 550
  • So you're saying, I **don't have to** define "self" as my first parameter in any of my functions/methods? – TeddyB Aug 16 '10 at 01:44
  • @TeddyB, no, what @Amber wrote was that you do not have to name it "self" -- you're free to name it whatever you like. The first parameter of a class method will always be passed a reference to the instance. – Andrew Aug 16 '10 at 02:18