514
you are viewing a single comment's thread
view the rest of the comments
[-] WolfLink@sh.itjust.works 40 points 1 day ago

In Python, self is not a keyword, it’s a conventional variable name. You can replace all instances of “self” with “this” and your code will work the same.

[-] jsomae@lemmy.ml 5 points 1 day ago

Lua might have been a better choice, since self is special in lua.

[-] diemartin@sh.itjust.works 2 points 1 day ago

Kinda.

Lua defines it implicitly only when you use the

function foo:bar(a, b, c) -- note the colon

syntactic sugar, which gets translated to

function foo.bar(self, a, b, c)` -- note the period

In all other cases, self is a regular variable name. You can even redeclare a new local with that name even when the old one is in scope.

[-] jsomae@lemmy.ml 2 points 23 hours ago

I don't see how what you said is inconsistent with me saying "self" is special in lua. Note that I did not say it's a keyword.

[-] SkyNTP@lemmy.ml 7 points 1 day ago

Python is just distancing itself from JS.

this post was submitted on 08 Jun 2025
514 points (97.8% liked)

Programmer Humor

36296 readers
524 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS