Python underscore as a function parameter
identifier, metasyntactic-variable, parameters, python
Solution
From what I've been able to figure out, it seems like this is the case:
`_` is used to indicate that the input variable is a throwaway variable/parameter and thus might be required or expected, but will not be used in the code following it.
For example:
# Ignore a value of specific location/index
for _ in range(10)
print("Test")
# Ignore a value when unpacking
a,b,_,_ = my_method(var1)
(Credit to this post)
The specific example I came across was this:
def f(_):
x = random() * 2 - 1
y = random() * 2 - 1
return 1 if x ** 2 + y ** 2 < 1 else 0
Problem
I have a python specific question. What does a single underscore `_` as a parameter means? I have a function calling `hexdump(_)`. The _ was never defined, so I guess it has some special value, I could not find a reference telling me what it means on the net. I would be happy if you could tell me.