Anonymous functions are vital to any modern high level language.
I think most people get hung up on the word. If the keyword was changed from “lambda” to “fun” for example I think it wouldn’t be as obtuse to more intermediate developers.
To be honest I think the lambda does Python a service vs a disservice. It helps to illustrate that everything in Python is an object. Once you realize you can treat functions similarly to how you treat things like integers and strings your mind opens up to functional style. Assigning a function to a variable the same way you do with a string, for instance, helps to reinforce this concept.
The `__magic__` is about avoiding naming conflicts while still being explicit. It's a choice between magic or reserving a lot of names.
About self, it's so strange to define a method with 2 arguments and call it with only one. Not only it's strange, it feels the opposite of being explicit. Most other languages manage to do without that self (Java, Ruby).
I run into another oddity today. Yesterday if forgot about
a = 0
if not a:
print("like in C")
I don’t think you’re wrong, but I am also not experienced enough to know why this would be the case. What is the virtue of having an anonymous function? I get that it makes code somewhat easier to read and write if you’re only using the function once and it’s short, but that seems like an edge case. What am I missing?
You are about to embark on a great adventure. I wish you luck on your quest!