The _ is variable name. Try it. (This variable name is usually a name for an ignored variable. A placeholder so to speak.)

Python:

>>> l = lambda _: True
>>> l()
<lambda>() missing 1 required positional argument: '_'

>>> l("foo")
True

So this lambda does require one argument. If you want a lambda with no argument that always returns True, do this:

>>> m = lambda: True
>>> m()
True
Answer from user1907906 on Stack Overflow
🌐
Reddit
reddit.com › r/python › acceptable use cases for lambda functions without arguments?
r/Python on Reddit: Acceptable use cases for lambda functions without arguments?
December 5, 2022 -

I’ve seen several sources that say using Python’s lambda functions without any arguments is a bad idea and “abuse of this feature”, but I think there are (at least) 2 valid use cases for it:

  1. When writing a function that has a callable as an argument, but you want the same output from it every time. For example, collections.defaultdict takes in a callable and a map as arguments. If I’m making some sort of game AI, having the default always be infinity or negative infinity can be useful when designing its decision making.

  2. When writing a dictionary/list where the values/elements are functions. You want to do something that’s not just returning a value when you call dictkey/listindex but you don’t want to define another function, and it you don’t want to take in an argument because another function in the dict already doesn’t.

Do you agree with this or are there much simpler solutions to this?

Discussions

python - Lambda expressions with no parameters in Haskell and / or lambda calculus - Software Engineering Stack Exchange
So, I was expecting that Haskell ... without parameters because the language is already lazy and there is no need to build delayed expressions. To my surprise, I found out that in Haskell it is possible to write the lambda expression ... Applying this function to any argument other than () throws an exception (at least as far as I could see during my tests). This seems different from delayed evaluation in Scheme and Python, because the ... More on softwareengineering.stackexchange.com
🌐 softwareengineering.stackexchange.com
September 23, 2014
Without `pass` and `...`, are there better ways to intend “Do nothing“ with a lambda?
Some uses pass statement to intend “Do nothing“ and some uses Ellipsis(…) to intend “Later impliment code“ according to the article and the article. But pass cannot be used with a lambda to intend “Do nothing“ while Ellipsis(…) can but it intends “Later impliment code“ and ... More on discuss.python.org
🌐 discuss.python.org
5
0
December 23, 2025
What is the purpose of Lambda expressions?
This is a typical example for beginners: x=lambda n:2*n print(x(7)) Otherwise I would create a function: def dbl(n): return 2*n print(dbl(7)) Of course: I can write simply 2*7, but the idea is to save a complex formula in an object once, and reuse it several times. More on discuss.python.org
🌐 discuss.python.org
19
1
December 8, 2021
Why not real anonymous functions? - Ideas - Discussions on Python.org
For whatever reason I often find myself writing code like this: def returns_a_func(this_var_gets_used): def _inner_func(*args, **kwargs): """Do some stuff in here""" return _inner_func Or like this: def some_useful_func(*args, **kwargs): """Does useful and interesting things, I promise""" ... More on discuss.python.org
🌐 discuss.python.org
4
January 30, 2024
🌐
AskPython
askpython.com › python › python-lambda-anonymous-function
Python Lambda Anonymous Function - AskPython
April 18, 2026 - Yes. lambda: 42 creates a function that takes no arguments and returns 42. I have been working on Python programming for more than 12 years. At AskPython, I share my learning on Python with other fellow developers.
🌐
The Python Coding Stack
thepythoncodingstack.com › the python coding stack › what's all the fuss about `lambda` functions in python
What's All the Fuss About `lambda` Functions in Python
February 15, 2025 - Instead, you enclose the expression in parentheses, and you can treat it just like you would treat a standard function name: add (10) to call the function with 10 as the argument.
🌐
DEV Community
dev.to › divshekhar › python-lambda-function-po3
Python Lambda Function - DEV Community
June 19, 2023 - A lambda function in Python can have any number of arguments, including zero arguments. Lambda function with no arguments performs a simple operation without needing any inputs.
🌐
W3Schools
w3schools.com › python › python_lambda.asp
Python Lambda
Python Examples Python Compiler ... Python Study Plan Python Interview Q&A Python Bootcamp Python Training ... A lambda function is a small anonymous function. A lambda function can take any number of arguments, but can only have one expression....
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-lambda-anonymous-functions-filter-map-reduce
Python Lambda Functions - GeeksforGeeks
Lambda functions are small anonymous functions, meaning they do not have a defined name.
Published   May 18, 2026
🌐
Real Python
realpython.com › python-lambda
How to Use Python Lambda Functions – Real Python
December 1, 2023 - The Python lambda function could have been written as lambda x=n: print(x) and have the same result. The Python lambda function is invoked without any argument on line 7, and it uses the default value n set at definition time.
Top answer
1 of 3
14

Well, the other answers cover what \() -> "something" means in Haskell: an unary function that takes () as argument.

  • What is a function without arguments? – A value. Actually, it can occasionally be useful to think of variables as nullary functions that evaluate to their value. The let-syntax for a function without arguments (which doesn't actually exist) ends up giving you a variable binding: let x = 42 in ...

  • Does lambda calculus have nullary functions? – No. Every function takes exactly one argument. However, this argument may be a list, or the function may return another function that takes the next argument. Haskell prefers the latter solution, so that a b c is actually two function calls ((a b) c). To simulate nullary functions, you have to pass some unused placeholder value.

2 of 3
9

You're misinterpreting what () means in Haskell. It isn't the lack of a value, it is rather the only value of the Unit type (the type itself being referred to by an empty set of parentheses ()).

Since lambdas can be constructed to use pattern matching, the lambda expression \() -> "s" is explicitly saying "create an anonymous function, expecting an input that matches the () pattern". There isn't much point to doing it, but it's certainly allowed.

You can use pattern matching with lambdas in other ways as well, for example:

map (\(a, b) -> a + b) [(1,2), (3,4), (5,6)] -- uses pattern matching to destructured tuples

map (\(Name first _) -> first) [Name "John" "Smith", Name "Jane" "Doe"] -- matches a "Name" data type and its first field

map (\(x:_) -> x) [[1,2,3], [4,5,6]] -- matches the head of a list
🌐
Python.org
discuss.python.org › python help
Without `pass` and `...`, are there better ways to intend “Do nothing“ with a lambda? - Python Help - Discussions on Python.org
December 23, 2025 - Some uses pass statement to intend “Do nothing“ and some uses Ellipsis(…) to intend “Later impliment code“ according to the article and the article. But pass cannot be used with a lambda to intend “Do nothing“ while Ellipsis(…) can but it intends “Later impliment code“ and I can still use a string to intend “Do nothing“ but it’s long as show below: v1 = lambda: pass # Error v2 = lambda: ... # No error v3 = lambda: "Do nothing" # No error So, are there better ways to intend...
🌐
Python.org
discuss.python.org › python help
What is the purpose of Lambda expressions? - Python Help - Discussions on Python.org
December 8, 2021 - This is a typical example for beginners: x=lambda n:2*n print(x(7)) Otherwise I would create a function: def dbl(n): return 2*n print(dbl(7)) Of course: I can write simply 2*7, but the idea is to save a complex fo…
🌐
Medium
medium.com › @imdshekhar › python-lam-4554550c0cd8
Python Lambda Function. In Python, developers use lambda… | by Divyanshu Shekhar | Medium
June 19, 2023 - A lambda function in Python can have any number of arguments, including zero arguments. Lambda function with no arguments performs a simple operation without needing any inputs.
🌐
Trey Hunner
treyhunner.com › 2020 › 01 › passing-functions-as-arguments
Passing a function as an argument to another function in Python
January 14, 2020 - Lambda functions are just like all other function objects: neither is more special than the other and both can be passed around · All functions in Python can be passed as an argument to another function (that just happens to be the sole purpose of lambda functions).
🌐
Python Basics
python-basics-tutorial.readthedocs.io › en › latest › functions › lambda.html
Lambda functions - Python Basics
October 25, 2025 - In Python, a lambda function is an anonymous function, that is, a function that is declared without a name. It is a small and restricted function that is no longer than one line. Like a normal function, a lambda function can have several arguments, ...
🌐
freeCodeCamp
freecodecamp.org › news › python-lambda-function-explained
How the Python Lambda Function Works – Explained with Examples
December 17, 2024 - They're commonly referred to as anonymous functions. Lambda functions are efficient whenever you want to create a function that will only contain simple expressions – that is, expressions that are usually a single line of a statement.
🌐
Python.org
discuss.python.org › ideas
Why not real anonymous functions? - Ideas - Discussions on Python.org
January 30, 2024 - For whatever reason I often find myself writing code like this: def returns_a_func(this_var_gets_used): def _inner_func(*args, **kwargs): """Do some stuff in here""" return _inner_func Or like this: def some_useful_func(*args, **kwargs): """Does ...
🌐
Quora
quora.com › What-are-anonymous-or-lambda-functions-and-their-syntax-in-Python
What are anonymous or lambda functions and their syntax in Python? - Quora
Answer: The functions in python are defined using a [code ]def[/code] keyword such as [code]def function_name(): ... ... return 0 [/code]While anonymous functions in Python are functions that defined without function name and using [code ] lambda[/code] keyword. These functions are c...
🌐
freeCodeCamp
freecodecamp.org › news › how-to-use-lambda-functions-in-python
Python Anonymous Function – How to Use Lambda Functions
February 15, 2023 - Without assigning a lambda function to a variable, you'd have something like this: print(lambda a,b : a + b) # <function <lambda> at 0x7f757922fb00> The code above simply returns a lambda object in the console.
🌐
DataFlair
data-flair.training › blogs › python-lambda-expression
Python Lambda Expression - Declaring Lambda Expression & Its Defaults - DataFlair
April 23, 2026 - It isn’t mandatory to provide arguments to a lambda expression in Python, it works fine without them.