Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
337 views
in Python by (155k points)
retagged by
How do I write a lambda function with no arguments?

Please log in or register to answer this question.

1 Answer

0 votes
by (155k points)

You can write a lambda function with no arguments in Python by simply omitting the arguments section in the lambda function definition. 

Here is an example:

f = lambda: print("Hello, world!")
f()
 

In this example, we define a lambda function that takes no arguments and simply prints "Hello, world!". We assign this function to the variable f, and then call f() to execute the function.

Note that even though the lambda function has no arguments, we still need to include the empty parentheses after the function name when we call it. This is because f() is a function call, and the parentheses are necessary to indicate that we want to execute the function.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...