Search this site
Embedded Files
AIMD GPDS Courses
  • Home
  • Courses
  • Contact
AIMD GPDS Courses
  • Home
  • Courses
  • Contact
  • More
    • Home
    • Courses
    • Contact

日本語  ❯

Lesson 4    ❮    Lesson List    ❮    Top Page

4.1 Functions    

❯  4.2  Lambda Functions    

4.3 Handling Exceptions    

4.4 Intro to RegEx    

4.5 RegEx for Data Cleaning

⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
EXPECTED COMPLETION TIME
❲▹❳  Video   9m 44s
☷  Interactive readings   5m
✑  Practice 4.2 (G Colab)   20m

Adding Return Values to a Function

To make a function return a value, use the return statement. Having a return value means you can save the result of the function into a  variable.

Making Lambda Function with Generator

A lambda function is a small anonymous function.

It can only have one expression and will also return that one expression. In this example, we will use a generator expression.

Making Lambda Function for Calculation

While you can add a generator expression, lambda functions are commonly used for simple calculation.

It can accept multiple arguments as well.

Using Function inside List Comprehension

Lambda functions are best for use for smaller functions (only one line of code). If a function is more than one line, it is recommended to use def instead.

Instead of writing a long list comprehension, you can split it into a lambda function and a shorter list comprehension.

©2023. All rights reserved.  Samy Baladram,
Graduate Program in Data Science - GSIS - Tohoku University
Google Sites
Report abuse
Page details
Page updated
Google Sites
Report abuse