In most object-oriented programming languages, we can refer to the newly created object and its methods with `this`; ‘this’ is a special keyword in many programming languages. It is a keyword that references the current object. This allows us to write class methods that make modifications to an object. Without it, we would not be able to make changes to the object internally. Here’s an example:

As you can see in the Javascript example, we use `this` in the constructor to add properties to our object when we create it using the `new` keyword.  Our methods use the this keyword to update the name property at the name of the code as well. Python shows a similar pattern with only one or two fundamental changes.


In Python, `this` is replaced with a new keyword `self`. They fundamentally do the same thing. The only difference is the spelling of the keyword. Take a look at this example:

As you can see the two examples are not that different from each other. If you look closely, they both have a similar pattern when constructing the class. The only difference here is that in Python we have to use the `self` keyword to do the same thing we would do in Javascript. But, this applies to programming languages as a whole; each programming language follows this pattern if they follow the object-oriented paradigm.

Advice For Any Language

My advice to you is to not just learn a programming language, but also understand the paradigm it belongs to; understanding a paradigm helps you gain clarity on different ways to program. That way you can spot the patterns across languages; programming languages come and go, but the way people program is here to stay. With that, key tool, you can get up and running in a language very quickly.Stay tuned for more posts on Python and programming!

%d bloggers like this: