Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Lambda Functions in Python | Section
/
Python Functions
セクション 1.  15
single

single

bookLambda Functions in Python

メニューを表示するにはスワイプしてください

Lambda functions are anonymous functions, meaning they don't have a name. They are created using the lambda keyword and are often used to define short functions where you can specify a function on the spot.

The basic syntax of a lambda function is as follows:

lambda arguments: expression
  • lambda: the keyword indicating the start of a lambda function definition;
  • arguments: the list of arguments the function takes;
  • expression: the expression executed when the function is called. The result of the expression is returned as the function's value.

The key feature of lambda functions is their concise syntax. They are convenient when you need to define a simple function without writing a lot of code.

123
square = lambda x: x**2 result = square(5) print(result)
copy
タスク

スワイプしてコーディングを開始

There is a list of prices (prices), and a lambda expression needs to be implemented that takes a price as a parameter and deducts 13% tax from it.

  • Define a lambda expression using the lambda keyword.
  • The lambda expression should take one parameter (price).
  • If the price is negative, consider it invalid and return 0 using the max() function directly within the lambda expression.
  • The lambda should first check the price and then deduct 13% from the valid amount.
  • Use a list comprehension to apply apply_tax to each element in prices.

解答

Switch to desktop実践的な練習のためにデスクトップに切り替える下記のオプションのいずれかを利用して、現在の場所から続行する
すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  15
single

single

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

some-alt