0

Emmanuel Katto Dubai : Using Conditional and Looping Constructs in Python lambda Functions

Hi Team, I'm Emmanuel Katto from Dubai, United Arab Emirates (UAE), I've come across an example where a Python lambda function is defined as: f = lambda x: x * x for x in range(10) However, I’ve read that Python is not a strict language, so there's flexibility to include constructs like if statements or for loops within lambda functions. I was wondering if you could clarify whether it's possible to use conditional (if) or looping (for) statements inside a lambda expression. Additionally, I’ve seen references to this concept in the Deitel Python book (which covers data science and AI), particularly in higher versions. If anyone has experience or further insights into using these constructs effectively within lambda functions, I’d appreciate your feedback! Thanks in advance! Best regards, Emmanuel Katto

5th Nov 2024, 5:41 AM
Emmanuel Katto
2 Antworten
+ 2
bot
5th Nov 2024, 2:20 PM
Lisa
Lisa - avatar
+ 1
Hello Emmanuel Someone asked this question just yesterday, I saw both that and your post asked about the same concern and referred the same book from Deitel :-) https://www.sololearn.com/en/Discuss/3307117/can-JUMP_LINK__&&__python__&&__JUMP_LINK-lambda-contain-the-statement
5th Nov 2024, 2:04 PM
Ipang