開始使用免費開始

定義 lambda 表達式

來寫幾個 lambda 表達式吧!這裡有三個小任務:每個都需要你定義一個接收一些參數的 lambda,並用它們計算出指定的結果。

本練習屬於課程

Python 程式面試題實作練習

檢視課程

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Take x and return x squared if x > 0 and 0, otherwise
squared_no_negatives = ____
print(squared_no_negatives(2.0))
print(squared_no_negatives(-1))
編輯並執行程式碼