Member-only story
5 Useful Advanced Features of Python
Python is a popular and beautiful programming language used in data science, web development, maths, etc. It is simple to use and beginner-friendly to learn. But are you sure you know all the cool features it has to offer?
Today I’m going to show 5 common advanced topics/features in Python that you should learn.
1. Lambda Functions
In Python, a lambda function is an anonymous function (a nameless function) that can take any number of arguments. It can only contain a single expression.
For instance, here is a lambda that multiplies a number by four:
lambda x : x * 4
To use this lambda, you can assign it to a variable:
mult4 = lambda x : x * 4
mult4(15.0) # returns 60
Or you can call it right away:
(lambda x : x * 4)(15.0) # returns 60.0
Lambda functions are useful when the functionality is needed for a short while. In such a case, you don’t want to waste resources by creating a separate method.
Lambda Example
Let’s filter a list of numbers using the built-in filter()
method. It takes two parameters:
- A filtering function (a lambda function in this case)