Hacker News new | ask | show | jobs
by jogloran 5011 days ago
Ruby also lets you do this in function definitions. Python doesn't special-case the underscore like Ruby does -- while I have occasionally wished otherwise, it is at least consistent with Python's language design principles that the special case doesn't exist.
1 comments

I don't have a source for this, but it is my understanding that, even though the python interpreter doesn't special-case the "_" variable name, it is a convention to use the underscore in the same situations in python as are described in ruby in the article.
Apart from the special meaning of the underscore in interactive mode, and the function _() in Django, I don't think it's common to use _ as a placeholder in Python. I sometimes do it regardless, hoping its meaning should be clear enough, but it's less suitable than in Ruby because you can't use it to ignore multiple arguments.