It essentially is a way of ignoring
the value of the variable, and we don't want to use it down the line.
Another way of thinking is that it is a placeholder for the value that will be ignored
def func(a, b):
return a,b
#I care about both return values
c,d = func(2,3)
#I don't care about the second returned value, so I put a _ to ignore it
c, _ = func(2, 3)
Another good use case of this is when you are running a for loop, but don't care about the index.
for _ in range(10):
#do stuff
Even for functions, it acts like a don't care variable
def func(a, _):
print(a)
func(1, 5)
The output will be 1