0
Why do we use 'self' in python and not 'this', like many other languages do?
Coding languages that support object-orienteted programming usually have a keyword to reference the object by which the method is called. In most of the coding languages I've met so far (C++, Java, Js) this keyword is hardcoded and it is 'this'. In Python, instead, this word can be chosen by the coder, but it is recommended to use the conventional 'self'. As 'self' can be changed, why don't all coders just write 'this' also in Python, so that the word is the same for each language? Is there a reason for that?
1 Answer
+ 1
As with many things, this is a matter of convention.
While languages inspired from C++ use 'this', like Java, C#, or PHP, there are other languages which use 'self', such as Python, Perl, Ruby, Rust, or even Swift. Visual Basic uses 'Me'.
So no, not all languages use 'this', just the languages you encountered this far.
Hopefully that answered your question (a bit late after 9 months, but still)