Member-only story

5 Advanced Python Concepts: Explanations and Applications

Lambda functions, comprehensions, generators, decorators, and hashability

Yong Cui
Better Programming

--

Photo by NASA on Unsplash

When you have developed a good understanding of basic data structures and their key functionalities, it’s time to explore some more advanced techniques in Python. In this article, I’d like to review five concepts that you can take advantage of in your code.

1. Lambda Functions

Lambda functions are also called anonymous functions in Python. Some people simply refer to them as lambdas. They have the following syntax: lambda arguments: expression. In essence, we use the lambda keyword to signify the declaration of a lambda function. Then we list the arguments, the number of which can be zero or more. After the colon, we list the expression that uses these arguments for any applicable operations.

Lambda functions are particularly useful in cases where we need to have a short one-time use function. For instance, several built-in functions have the key argument, to which we can set a lambda function.

--

--

Responses (1)

Write a response