Part of the reason I’m learning Python is to do things in AWS Lambda. Most tutorials and examples use Python, that, along with it being an easy language to learn it is why I’m doing this blog. Another reason was I needed to do something in GSuite for work the other day, create a Python command-line application that makes requests to the Directory API. I got a strange error and had no idea how troubleshoot it or even how to fix it.  It felt like a job requirement at this point to learn what I could.

I was reading the functions chapter in “Python Programming Illustrated for Beginners and Intermediates” by William Sullivan. The ebook is $2.99 on Amazon and it’s short with quick read chapters to give context so I can use other resources with a better understanding.  I skipped right to functions and part way through, I’m reading about anonymous functions. This sentence popped out at me:

The anonymous functions are created using lambda expressions and cannot contain multiple expressions.

This is the first time I recall hearing anonymous functions are called lambdas! How did I not know this? Here is an example of a lambda.

>> total = lambda var1, var2, var3: var1 * var2 + var3
>>> print(total(2,4,6))
14

 

Wee Bay looking shocked

Mind Blown

Lambdas are just regular old anonymous functions; a single line of code. They don’t have names like when defining a function using the def keyword. They are more like expressions than functions. Lambdas have two rules:

  1. Lambdas must be only one expression.
  2. The expression being evaluated is always returned.
Syntax:  lambda argument : expressions

I’m not finished reading about functions and I haven’t completed the functions section in the Linux Academy yet. I just had to stop and drop this gem into the blog for perpetuity

,Animation of star over words today I learned