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
python 3.x - What if the lambda function does not have any argument in python3? - Stack Overflow
I'm confused about the lambda here. I only know lamnda x: x+1. Usually, we have an argument for lambda. What if we don't have argument like this code? ... Save this answer. Show activity on this post. Lambda function can be used efficiently even without the lambda variable in python. More on stackoverflow.com
🌐 stackoverflow.com
Acceptable use cases for lambda functions without arguments?
Imo you’ve found some outliers - and I wouldn’t worry about why others think! While True: Has use cases after all More on reddit.com
🌐 r/Python
7
6
December 5, 2022
[SymPy] Confused with lambda function arguments

What exactly is the problem you're trying to solve?

More on reddit.com
🌐 r/learnpython
12
5
September 15, 2015
🌐
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.
🌐
Python Examples
pythonexamples.org › python-lambda-function-without-arguments
Python Lambda Function without Arguments
In Python, you can define a lambda function without any arguments by using an empty parameter list.
🌐
AskPython
askpython.com › home › python lambda – anonymous function
Python lambda - Anonymous Function - AskPython
September 5, 2019 - Yes, we can define a lambda function without any argument. But, it will be useless because there will be nothing to operate on.
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
🌐
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.
🌐
Tutorial Teacher
tutorialsteacher.com › python › python-lambda-function
Lambda Functions and Anonymous Functions in Python
We can declare a lambda function and call it as an anonymous function, without assigning it to a variable. ... Above, lambda x: x*x defines an anonymous function and call it once by passing arguments in the parenthesis (lambda x: x*x)(5). In ...
Find elsewhere
🌐
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.
🌐
CopyProgramming
copyprogramming.com › howto › python-lambda-functoin-without-argument-code-example
Python Lambda Function Without Arguments: Code Examples and 2026 Best Practices - Python lambda function without arguments code
December 27, 2025 - Python's official documentation confirms lambdas support zero parameters, evaluating the body at runtime without late-binding issues since no free variables are captured unless defaults are used. For instance, greet = lambda: "Hello World" assigns a reusable function that prints or returns a fixed greeting when invoked. Lambda functions without arguments are straightforward to implement and use in everyday Python code...
🌐
Toppr
toppr.com › guides › python-guide › references › methods-and-functions › anonymous-function › python-lambda-anonymous-function
Python Lambda (Anonymous) Function: Definition and Examples
July 14, 2021 - If you want to use the Python lambda (anonymous) function, you will have to follow this syntax: ... The lambda function can have any number of arguments, or no arguments at all, after the colon (:). When you call the lambda function, you will ...
🌐
W3Schools
w3schools.com › python › python_lambda.asp
Python Lambda
Python Examples Python Compiler ... A lambda function is a small anonymous function. A lambda function can take any number of arguments, but can only have one expression....
🌐
Programiz
programiz.com › python-programming › anonymous-function
Python Lambda/ Function (With Examples)
Before you learn about lambdas, make sure to know about Python Functions. We use the lambda keyword instead of def to create a lambda function. Here's the syntax to declare the lambda function: ... Here, we have defined a lambda function and assigned it to the variable named greet.
🌐
DataFlair
data-flair.training › blogs › python-lambda-expression
Python Lambda Expression - Declaring Lambda Expression & Its Defaults - DataFlair
March 8, 2021 - It isn’t mandatory to provide arguments to a lambda expression in Python, it works fine without them. ... Another example would be where the expression is a print statement. ... Hence, we conclude that omitting arguments is acceptable.
🌐
The Python Coding Stack
thepythoncodingstack.com › p › whats-all-the-fuss-about-python-lambda-functions
What's All the Fuss About `lambda` Functions in Python
December 1, 2023 - 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. You could name a lambda function if you really wanted to. But if you feel the need to name a lambda function, you probably should use a standard function instead. Anyway, here's how you would name a lambda function if you're stubborn enough to do so: And that's all there is, really. Python's lambda functions are just functions with no name...
🌐
Scaler
scaler.com › home › topics › lambda function in python
Lambda Function in Python (with Examples) - Scaler Topics
February 2, 2024 - Python's lambda function is a ... in functional programming constructs. A lambda function can take any number of arguments including no argument, but they contain only one expression....
🌐
Stack Abuse
stackabuse.com › lambda-functions-in-python
Lambda Functions in Python
May 16, 2023 - This creates an anonymous function that receives as input the variables x_1, ..., x_n and returns the evaluated expression(x_1, ..., x_n). ​ The purpose of lambda functions is to be used as parameters for functions that accept functions as parameters, as we did with map() above. Python allows you to assign a lambda function to a variable, but the PEP 8 style guide advises against it.
🌐
Hyperskill
hyperskill.org › university › python › lambda-functions-in-python
Lambda Functions in Python
July 17, 2024 - It essentially creates a new list that contains the modified values. To define the modification to be applied to each element, we can use a lambda function. A lambda function is a small anonymous function that can take any number of arguments but can only have one expression.